Running your app on Kubernetes: Part 1 — Build an image of MLFlow App on OpenShift

Sindhu Murugavel
5 min readJul 2, 2020

--

There is a lot of documentation on the Internet but it takes a lot of time to sift through for any beginner(like me!). Here’s to building your simple app on Kubernetes in 8 steps.

MLFlow is an open source AI/ML Lifecycle platform. Source code is on GitHub here. Below are the steps to build an image of MLFlow on OpenShift.

Pre-condition:

You need to have a containerization environment in-place. If not, follow my article on Getting started with Kubernetes to set it up. Now you are ready to start!

Step 1: Create a Red Hat Developer Account

You need to have a Red Hat developer account for downloading their ready-to-use container images. To create an account, click here.

Step 2: Create a Red Hat Service Account to get OpenShift Secret

A secret is a key/token that is almost like a password(only its not!). It can help you connect two different environments. Here it is to connect your Openshift environment to the Red Hat container registry to pull the base image that we are going to use in the next steps.

After creating the developer account, open the registry-service in Red Hat using the same login. Click the blue “New Service Account” button on the right.

Logging into Red Hat Registry Service

Provide a reasonable name and description and click “Create”.

Creating a new registry service account

The registry account that you created now will have 3 main options to add to any environment — Token, OpenShift Secret & Docker. We will be using the token approach.

Account access patterns

Step 3: Setup a Red Hat Secret on OpenShift

Open the OpenShift UI console and select Workloads →Secrets. Click the blue “Create” button on the pane that appeared and select “From YAML”. Copy the contents of the YAML below and update the token value from the Red Hat registry service account created with the above step instead of the comment in the YAML and save it.

Secret.yaml

Step 4: Setup a Quay Registry account

You need to setup a repository to push and pull the container image during build and deploys. The relationship between registries and container images is very similar to nexus and jars. Some container repositories are Docker Hub and Quay. Quay is my registry of choice for this PoC. Create a Quay account and create a new repository in your account. Open the repository and on the left pane click on the robot symbol. On the top right, click “Create Robot Account”. Provide a reasonable name and description and create the robot account.

Create a new repository
Create a robot account

Step 5: Setup Quay Secret on OpenShift

Once the robot account is created, open it and select “Kubernetes Secret” on the left pane. Click on view YAML option and copy the contents of the YAML shown.

Create a Kubernetes Secret for the Robot account

Open the OpenShift UI console and select Workloads →Secrets. Click the blue “Create” button on the pane that appeared and select “From YAML”. Paste the Robot Account Secret YAML and save it.

Step 6: Identify your builder image

The base/builder image should be identified based on the type of application being deployed. In my case, MLFlow is a python application so my choice was a RedHat Python Image — Python 3.8.

The usage of the image is directly in the Build Config’s Dockerfile section since this is a pretty basic build(No need to import — just use directly!)

Selecting your builder image

Step 7: Create a Build Configuration

This is the core step to getting your image built right and it is the toughest step.Below is a starting point for a smooth start. Update the name of your Red Hat secret and container registry secret created in the above steps in the YAML below.

BuildConfig.yaml

The source section of the YAML decides how the build is well, built! My build does not have any git code that needed to be built since MLFlow is available as a python package that can be pip installed. This can be done with a simple embedded docker file approach. Since the MLFlow tracking server has a UI, there is a need to expose the URL port to be used outside the container as the last step and update the host name as well. You can provide your app’s installation flow in the Dockerfile section of the Build Config.

Open the OpenShift UI console and select Builds →Build Config. Click the blue “Create Build Config” button on the pane that appeared and paste the updated YAML in the box and save it.

Create a build config on Openshift

Step 8: Build

You are almost there! In the OpenShift UI, select Builds →BuildConfig. Click on your three dots on your chosen build config and start build. Monitor your builds under Builds →Builds.

Starting a build on Openshift
Monitoring your build

You have successfully built an image of MLFlow on OpenShift. Next is Deployment!!

--

--

Sindhu Murugavel
Sindhu Murugavel

Written by Sindhu Murugavel

Bringing Tech and Principles together!

No responses yet