Create Custom Kale Image

This guide will walk you through creating a custom Kale image. It assumes that you have an Arrikto-provided signed URL which downloads a tarball containing all Kale, KFP and Rok wheels.

What You’ll Need

  • An Arrikto EKF or MiniKF deployment.
  • An Arrikto-provided signed URL for a tarball containing Kale, KFP and Rok wheels.

Contact Arrikto

If you don’t have a signed URL provided by Arrikto, please contact the Arrikto Tech Team to create one for you. You need to provide them with:

  • Your EKF version. Look at the bottom left of the Central Dashboard for this information.
  • Your desired Python version.

Procedure

  1. Create a new kaleimg directory to collect everything required for the docker build context:

    user@workstation:~$ mkdir kaleimg && cd kaleimg

    Important

    The new directory works as a new, fresh, and clean environment for the docker build procedure, avoiding trouble with unrelated files and their permissions. Therefore, do not skip this step, it is mandatory.

  2. Specify the Arrikto-provided signed URL for the tarball:

    user@workstation:~/kaleimg$ export ARRIKTO_TARBALL_URL="<ARRIKTO_TARBALL_URL>"

    Replace <ARRIKTO_TARBALL_URL> with the URL that Arrikto provided you with.

  3. Find the tarball file name:

    user@workstation:~/kaleimg$ export TARBALL=$(basename ${ARRIKTO_TARBALL_URL?} | cut -f1 -d?)
  4. Use the Arrikto-provided URL to download the tarball:

    user@workstation:~/kaleimg$ wget -O ${TARBALL?} ${ARRIKTO_TARBALL_URL?} ... 2022-02-15 12:50:42 (14.6 MB/s) - ‘kale-py38-develop-l0-release-1.5-pre-399-g951df00ac.tgz’ saved [10552691/10552691]
  5. Inspect the downloaded tarball and verify that this is a flat directory named after the Python and EKF version and it includes wheels:

    user@workstation:~/kaleimg$ tar tzf ${TARBALL?} kale-py38-develop-l0-release-1.5-pre-399-g951df00ac/ kale-py38-develop-l0-release-1.5-pre-399-g951df00ac/rok_ddns_client-1.5rc0.post0+399.g951df00ac-py38-none-any.whl ...
  6. Extract the downloaded tarball:

    user@workstation:~/kaleimg$ tar xzvf ${TARBALL?} kale-py38-develop-l0-release-1.5-pre-399-g951df00ac/ kale-py38-develop-l0-release-1.5-pre-399-g951df00ac/rok_ddns_client-1.5rc0.post0+399.g951df00ac-py38-none-any.whl ...
  7. Find the extracted directory:

    user@workstation:~/kaleimg$ export WHEELS=$(basename ${TARBALL?} .tgz)
  8. Move wheels to the wheels directory:

    user@workstation:~/kaleimg$ mv $WHEELS wheels/
  9. Build and push your custom Python image using the above wheels and make Kale in your Notebook use it.

    1. Create a Dockerfile.python file:

      user@workstation:~/kaleimg$ touch Dockerfile.python
    2. Edit Dockerfile.python and paste this Dockerfile snippet to install the Rok, Kale and KFP wheels in your Python image. Set python_version to the same Python version you have picked for the Kale Wheels.

      ARG python_version=<python-version> FROM python:${python_version} ARG python_version # Upgrade pip: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=928275 RUN python3 -m pip --no-cache-dir install --upgrade pip setuptools COPY wheels /wheels # Install Rok RUN pip install --find-links /wheels rok-gw-client rok-kubernetes && \ rok --help # Install Kale RUN pip install /wheels/kubeflow_kale-*.whl # IMPORTANT: Install KFP after Kale, because Kale fetches KFP from # PyPI and we want to override that with Arrikto's fork RUN pip install /wheels/kfp-*.whl
    3. Specify the Python Dockerfile path:

      user@workstation:~/kaleimg$ export DOCKERFILE_PYTHON="Dockerfile.python"
    4. Specify the Python image name:

      user@workstation:~/kaleimg$ export PYTHON_KALE_IMAGE="gcr.io/my-project/python-kale:v1"

      Replace gcr.io/my-project/python-kale:v1 with an image name of your choice.

      Important

      Do not use the latest tag in your images. It is bad practice and you should definetely avoid it. The main reason is that the latest tag doesn’t make the image reproducible. Operations like deploying a new version of your app, or rolling back are not possible.

    5. Specify the Python version of your wheels:

      user@workstation:~/kaleimg$ export PYTHON_VERSION="<PYTHON_VERSION>"

      Replace <PYTHON_VERSION> with the Python version of your wheels.

    6. Build the Python image:

      user@workstation:~/kaleimg$ docker build --build-arg python_version=${PYTHON_VERSION?} -t ${PYTHON_KALE_IMAGE?} -f ${DOCKERFILE_PYTHON?} .
    7. Push the new Python image:

      user@workstation:~/kaleimg$ docker push ${PYTHON_KALE_IMAGE?}
    8. Follow the Configure Custom Kale Python Image guide to configure Kale to use your new custom Python image. Then, return to this guide and proceed with the rest of it.

  10. Build and push your custom notebook image using the above wheels.

    1. Create a Dockerfile.nb file:

      user@workstation:~/kaleimg$ touch Dockerfile.nb
    2. Edit Dockerfile.nb and paste this Dockerfile snippet to install the Rok, Kale and KFP wheels starting from your own base image.

      FROM <base-image> USER root # Upgrade pip: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=928275 RUN python3 -m pip --no-cache-dir install --upgrade pip setuptools RUN pip3 install "jupyterlab>=3,<4" COPY wheels /wheels # Install Rok RUN pip3 install --upgrade --find-links /wheels rok-gw-client rok-kubernetes && \ rok --help # Install Kale RUN pip3 install /wheels/kubeflow_kale-*.whl # IMPORTANT: Install KFP after Kale, because Kale fetches KFP from # PyPI and we want to override that with Arrikto's fork RUN pip3 install /wheels/kfp-*.whl # Install Kale JupyterLab extension RUN pip3 install /wheels/kubeflow_kale_labextension-*.whl # Set the entrypoint user back to `jovyan` USER jovyan

      Note

      The provided Dockerfile is inspired by the Jupyter-Kale image. Therefore, it assumes that certain users like jovyan and root exist. If you’re planning to use a completely different base image make sure to edit the Dockerfile accordingly.

    3. Specify the Dockerfile path:

      user@workstation:~/kaleimg$ export DOCKERFILE_NB="Dockerfile.nb"
    4. Specify the Jupyter image name:

      user@workstation:~/kaleimg$ export NB_KALE_IMAGE="gcr.io/my-project/notebook-kale:v1"

      Replace gcr.io/my-project/notebook-kale:v1 with an image name of your choice.

      Important

      Do not use the latest tag in your images. It is a bad practice and you should definetely avoid it. The main reason is that the latest tag doesn’t make the image reproducible. Operations like deploying a new version of your app, or rolling back are simply not possible.

    5. Build the Jupyter image:

      user@workstation:~/kaleimg$ docker build -t ${NB_KALE_IMAGE?} -f ${DOCKERFILE_NB?} .
    6. Push the new Jupyter image:

      user@workstation:~/kaleimg$ docker push ${NB_KALE_IMAGE?}
    7. Optional

      If you want to set your new image as a default choice on JWA, follow the Extend List of JWA Default Images guide. Then, return to this guide and proceed with the rest of it.

Verify

  1. Navigate to the Notebooks UI and create a notebook server with your new custom notebook image.

  2. Launch a new terminal.

  3. List Kale, KFP and Rok wheels in your environment and verify that all are in the desired version:

    jovyan@mynotebook-0:~$ pip3 list | grep -e rok -e kale -e kfp kfp 1.7.post0+41.gb3589b6c6 kfp-pipeline-spec 0.1.13 kfp-server-api 1.7.1 kubeflow-kale 0.6.post0+548.g82164514f kubeflow-kale-labextension 0.6.post0+548.g82164514f rok-common 1.5rc0.post0+399.g951df00ac rok-etcd-client 1.5rc0.post0+399.g951df00ac rok-gw-client 1.5rc0.post0+399.g951df00ac rok-kubernetes 1.5rc0.post0+399.g951df00ac rok-tasks 1.5rc0.post0+399.g951df00ac
  4. Verify that Kale uses your custom Python image:

    jovyan@mynotebook-0:~$ echo ${KALE_PYTHON_IMAGE?} gcr.io/my-project/python-kale:v1

Summary

You have successfully created a custom Kale image.

What’s Next

Check out how you can configure Kale to use the custom Python image that you just created.