VOOZH about

URL: https://thenewstack.io/tutorial-build-custom-container-images-for-a-kubeflow-notebook-server/

⇱ Tutorial: Build Custom Container Images for a Kubeflow Notebook Server - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2021-07-02 06:00:45
Tutorial: Build Custom Container Images for a Kubeflow Notebook Server
tutorial,
Kubernetes

Tutorial: Build Custom Container Images for a Kubeflow Notebook Server

In this KubeFlow tutorial, we will build an end-to-end machine learning pipeline for data preparation, training, and inference.
Jul 2nd, 2021 6:00am by Janakiram MSV
👁 Featued image for: Tutorial: Build Custom Container Images for a Kubeflow Notebook Server
This tutorial is the latest installment in an explanatory series on Kubeflow, Google’s popular open source machine learning platform for Kubernetes

In this installment, we will start exploring building an end-to-end machine learning pipeline for data preparation, training, and inference. We will delve deeper into these tasks over the next few installments.

To follow this guide, you need to have Kubeflow installed in your environment with a storage engine like Portworx supporting shared volumes for creating PVCs with RWX support.

We will train a Convolutional Neural Network (CNN) to classify the images of dogs and cats. The objective is not to train the most sophisticated model but explore how to build ML pipelines with Kubeflow Notebook Server. This scenario will be further extended to run MLOps based on Kubeflow Pipelines. For model serving, we will leverage KFServing, one of the core building blocks of Kubeflow.

In the first part of this series, we will build custom container images for the Kubeflow Notebook Server that we will use in the remainder of this tutorial.

Overview

There are three independent steps involved in this exercise: data preparation, model training, and inference. Each step is associated with a dedicated Jupyter Notebook Server environment. The data preparation and inference environments will target the CPU, while the Jupyter Notebook used for training will run on a GPU host.

Data scientists will perform the data processing task and save the final dataset to a shared volume used by machine learning engineers training the model. The trained model is stored in another shared volume used by DevOps engineers to package and deploy the model for inference.

The following image depicts how the Notebook Servers leverage the storage engine.

👁 Image

Each Jupyter Notebook Server uses its own container image with the appropriate tools and frameworks. This gives the teams the flexibility they need to run their respective tasks.

Once the custom container images are built, and storage is configured, our Kubeflow environment will look like the below screenshot:

👁 Image

While the whole pipeline can be executed with just one Notebook Server without shared folders, production deployments need isolated environments for each team.

Build the Container Images

Since each Notebook Server has a well-defined role, we will build dedicated images for each environment.

Let’s start with the image for data preparation and pre-processing. This will contain modules such as Pandas and Matplotlib useful for processing and analyzing data.

FROM ubuntu:18.04

RUN apt-get update && apt-get install -y \
python3 \
python3-pip

RUN python3 -m pip --no-cache-dir install --upgrade \
"pip<20.3" \
setuptools

RUN python3 -m pip install --no-cache-dir \
jupyter \
matplotlib \
pandas \
scipy \
imutils \
opencv-python

RUN apt-get install -y --no-install-recommends \
zip \
unzip \
wget \
git \
libgl1-mesa-glx

EXPOSE 8888

ENV NB_PREFIX /

CMD ["bash","-c", "jupyter notebook --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"]

Let’s call this file Dockerfile.prep

The commands used in the above Dockerfile are self-explanatory. We start with the base image of Ubuntu 18.04 and then install Python 3 along with Pip. We then install the required Python packages followed by the essential command-line tools. Finally, we expose port 8888 for accessing the Jupyter Hub web interface and launch the notebook with the right set of parameters.

If you are wondering why we are using the environment variable NB_PREFIX, then refer to the Kubeflow docs to understand how the controller uses the variable to configure the URL. Essentially, the Kubeflow notebook controller manages the base URL for the notebook server using the environment variable, NB_PREFIX.

Build the image and push it to Docker Hub or any other image registry.


docker build -t janakiramm/dataprep -f Dockerfile.prep .


docker push janakiramm/dataprep

It’s time for building the image for the training Notebook Server. We will use the latest TensorFlow image with support for GPU.

FROM tensorflow/tensorflow:latest-gpu-jupyter
RUN /usr/bin/python3 -m pip install --upgrade pip

RUN pip install pandas \
sklearn \
scipy \
matplotlib \
imutils \
opencv-python

RUN apt-get update
RUN apt-get install -y git \
wget \
libgl1-mesa-glx

ENV NB_PREFIX /

CMD ["sh","-c", "jupyter notebook --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"]

We start with the base image of TensorFlow GPU that comes with all the required CUDA libraries. We then install the required Python libraries and OS tools before exposing the Jupyter Notebook URL.

Build and upload this image to the registry.


docker build -t janakiramm/train -f Dockerfile.train .

Finally, for model serving and testing, we will create a TensorFlow CPU-based image.

FROM tensorflow/tensorflow:latest-jupyter
RUN /usr/bin/python3 -m pip install --upgrade pip

RUN pip install pandas \
sklearn \
scipy \
matplotlib \
imutils \
opencv-python

RUN apt-get update
RUN apt-get install -y git \
wget \
libgl1-mesa-glx

ENV NB_PREFIX /

CMD ["sh","-c", "jupyter notebook --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"]

Build and push the image to the registry.


docker build -t janakiramm/train -f Dockerfile.infer .


docker push janakiramm/infer

In the next part of this tutorial, we will configure the Kubernetes Storage Classes, Persistent Volumes required to run the Notebook Servers. Stay tuned.

TRENDING STORIES
Janakiram MSV (Jani) is a practicing architect, research analyst, and advisor to Silicon Valley startups. He focuses on the convergence of modern infrastructure powered by cloud-native technology and machine intelligence driven by generative AI. Before becoming an entrepreneur, he spent...
Read more from Janakiram MSV
SHARE THIS STORY
TRENDING STORIES
Portworx is a sponsor of The New Stack.
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.