All Products
Search
Document Center

Container Service for Kubernetes:Create and use notebooks

Last Updated:Nov 08, 2023

Data scientists can use the cloud-native AI suite to create Jupyter and Visual Studio (VS) Code notebooks to develop and debug machine learning algorithms, and submit these algorithms to Container Service for Kubernetes (ACK) clusters for model training. The cloud-native AI suite allows you to set up an AI development environment by deploying open source JupyterLab, custom Juypter notebook images, or custom VS Code notebook images in your ACK cluster, and integrate the configurations of the cloud-native AI suite with the permission management system of ACK. This topic describes how to create and use a notebook by using the cloud-native AI suite.

Prerequisites

Introduction to notebooks

  • Provide a machine learning experiment environment that can be integrated into a cloud platform. This environment allows you to develop machine learning models on your on-premises machine.

  • Provide a tool to copy and process datasets. This allows you to submit processed data to persistent storage. You can also process datasets by using big data tools.

  • Provide an environment for machine learning processes, such as model testing and data preprocessing. In the environment, you can write and debug the code of machine learning jobs, package the code into Docker images, and push the images to your cluster or remote Container Registry repositories.

Step 1: Create a notebook

  1. Log on to AI Developer Console. For more information, see Log on to AI Developer Console.

  2. In the left-side navigation pane of AI Developer Console, click Notebook.

  3. On the Notebook page, click Create notebook.

  4. In the Notebook message, Notebook configure, and Advanced Configuration sections, set the parameters and click Create notebook.

    create_notebook
    • In the Notebook message section:

      1. Set Notebook Name, Notebook Image, and Namespace. The selected namespace must be the one that the cluster administrator created for AI development. You can select the default notebook image or a custom notebook image. Configure other parameters based on your requirement.

        Note
        • When you specify Notebook Image, select the notebook image that meets your requirement. You need to select Jupyter notebook images for Jupyter notebooks and select VS Code notebook images for VS Code notebooks. Otherwise, your notebooks cannot function as normal.

        • Custom notebook images are available only in the current cluster. You cannot share custom notebook images to other clusters or users.

      2. Turn on Workspace PVC. Select the persistent volume claim (PVC) associated to the workspace from the Target PVC drop-down list.

      3. Turn on the Token switch to inject a custom token into the notebook to enhance its security. Only Jupyter notebooks support this feature.

      4. Specify Notebook Type to select an image launch method. Different types of notebooks require different environments. For example, if Notebook Type is set to Jupyter, a Jupyter notebook is created.

    • In the Notebook configure section, set CPU (Cores), Memory (GB), and GPU (Card Numbers).

    • In the Advance Configuration section, you can configure Label, Annotation, NodeSelector, and Toleration for your notebook.

  5. After the notebook is created, go to the Notebook page and click the created notebook to view the detailed information.

Step 2: Use a Jupyter notebook

Create and use a Jupyter notebook

  1. On the Notebook page, click the Jupyter notebook that is in the Running state.

  2. On the page that appears, click Python 3 in the Notebook section.

    Note

    On the create notebook page, the notebook images provided by ACK support only Python. If you want to use other languages, you can build custom notebook images from Docker files. For more information, see Create a custom notebook image.

    23
  3. Use Arena to submit a job in the notebook.

    Method 1: Use the Arena CLI to submit a job

    24

    Method 2: Use Arena SDK for Python to submit a job

    25

Use a VS Code notebook

  1. On the Notebook page, select a notebook in the Running state and click its name.

  2. The VSCode page provides a VS Code-like development experience same as an on-premises environment. The kubeconfig file of your cluster is injected into the notebook and environment variables are available for customization.

    image..png

Create a custom notebook image

Before you create a custom notebook image, you need to install the latest Arena component version in your Jupyter notebook or VS Code notebook. This allows you to run our demos in the notebook. For more information about how to install the Arena component, see Configure the Arena client.

Note

Custom notebook images are available only in the current cluster. You cannot share custom notebook images to other clusters or users.

Create a custom Jupyter notebook image

To meet various requirements, you can create custom Jupyter notebook images on the Notebook page of Jupyter Notebook, as shown in the following figure.

28

You can perform the following steps to create a Docker file and build an image:

Note

The version of jupyterlab installed in the image must be 3.0.0 or later.

FROM tensorflow/tensorflow:1.15.5-gpu
USER root
RUN pip install jupyter && \
    pip install ipywidgets && \
    jupyter nbextension enable --py widgetsnbextension && \
    pip install jupyterlab && jupyter serverextension enable --py jupyterlab
# Download and install Arena SDK for Python. 
RUN pip install arenasdk
# If you use other methods to install JupyterLab, you need to expose the Service through port 8888. 
EXPOSE 8888
USER jovyan

Create a custom VS Code notebook image

To meet various requirements, you can create custom VS Code notebook images on the Notebook page of VS Code Notebook, as shown in the following figure.

image..png

You can perform the following steps to create a custom Docker file and build an image:

FROM ubuntu:18.04
USER root

RUN apt update && \
  	apt install -y curl

RUN cd /opt && \
  	wget https://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/arena/install.sh && \
    /opt/install.sh

You need to modify the content of the Docker file based on the base image that you select to ensure that the image can be built.

Save a notebook as an image

In the AI Developer Console of the cloud-native AI suite, the ack-ai-dev-console component in version 1.0.22 or later allows you to submit a notebook as an image and save it to the host. This allows you to save the development environment of the notebook.

Note

This feature only supports notebook instances created by using the ack-ai-dev-console component of version 1.0.22 and later. You cannot perform this operation on existing notebook instances.

To save a notebook as an image, perform the following steps:

  1. Download the client binary tool for the ack-commit-agent component in Notebook. Click here to download the tool.

  2. Run the following command in Notebook to make the client globally executable:

    chmod +x ack-commit-ctl
    mv ack-commit-ctl /usr/bin/
  3. Use this tool to submit and save a notebook as an image. The following example shows how to submit an image.

    ack-commit-ctl commit image-commit-sample:v0.1.0-test
    INFO[0000] container id: xxx
    INFO[0002] Container save success, image: image-commit-sample:v0.1.0-test

    If the preceding output appears after the notebook is submitted, the notebook is saved as an image.

  4. Run the following command to specify the username and password of the image repository and push the image to the image repository:

    ack-commit-ctl push image-commit-sample:v0.1.0-test --username=username --password=password
    INFO[0000] Start pushing the image:  image-commit-sample:v0.1.0-test 
    INFO[0000] Waiting...                                   
    INFO[0003] Image pushed successfully: image-commit-sample:v0.1.0-test

    If the preceding output appears, the image is pushed to the image repository.

Use a saved image

  1. Make sure that the ack-ai-dev-console component is updated to 1.0.21 or later.

  2. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  3. On the Clusters page, click the name of the cluster that you want to manage and choose Workloads > Pods in the left-side navigation pane.

  4. On the Pods page, find the pod of the notebook which is saved as an image, and click the name of the pod. On the pod details page, you can obtain the name of the node on which the pod is deployed.

  5. Create a notebook on the Notebook page.

    1. In the Image Pull Secrets section, select the created notebook image. In the Advance Configuration section on the right side, set the NodeSelector. Set the key of NodeSelector to kubernetes.io/hostname and the value to the pod name obtained in Step 4.

    2. Click Create notebook. If the notebook can be created, the saved image is used.