After discussing on MLFlow in the last post, in today’s post, let’s have a look at Kubeflow
Architecture
Here is an overview of the MLOPS workflow with Kubeflow.
And in today’s post, we will focus on this part.
What is Kubeflow?
Kubeflow is an open-source machine learning (ML) toolkit for Kubernetes. It is dedicated to making deployments of machine learning workflows on Kubernetes simple, portable, and scalable. Kubeflow can facilitate the orchestration of Kubernetes ML workloads and to empower users to deploy best-in-class open-source tools on any Cloud infrastructure.
Deploying Kubeflow on GCP
Account Set up
Open cloud console
And then execute the below commands in GCP’s cloud shell
Setting up OAuth client
-
Navigate to https://console.cloud.google.com/apis/credentials/consent
-
Edit Application:
Authorised domain:
- On the credentials screen:
- Click Create credentials, and then click OAuth client ID.
- Under Application type, select Web application.
- In the Name box enter any name for your OAuth client ID. This is not the name of your application nor the name of your Kubeflow deployment. It’s just a way to help you identify the OAuth client ID.
The Client ID and Client Secret are generated.
In the Authorized redirect URIs box, enter the following (if it’s not already present in the list of authorized redirect URIs):
https://iap.googleapis.com/v1/oauth/clientIds/<client-id>.apps.googleusercontent.com:handleRedirect
Deploying Management cluster
- On cloud console
- Clone github repo
Note that, on the official kubeflow documentation, it mentioned that the repo needs to be clone again when deploy the kubeflow cluster, however, it is not necessary to clone the repo again.
Also, it maybe easier to run the below command in your local terminal instead of cloud shell. Since I found that the cloud shell is likely to lost connection while creating the cluster, since it takes a bit of time to create.
Go to kubeflow-distribution/management
directory for Management cluster configurations.
Configure Environment Variables
Fill in environment variables in
Run the followings:
Configure kpt setter values
Use kpt to set values for the name, project, and location of your management cluster. Run the following command:
Enable the Anthos API if it is not already enabled:
Deploy Management Cluster
- Deploy the management cluster by applying cluster resources:
- Create a kubectl context for the management cluster, it will be named
${MGMT_NAME}
:
- Grant permission to Config Controller service account:
Deploying Kubeflow cluster
- Run the following command to pull upstream manifests from
kubeflow/manifests
repository.
Environment Variables
Log in to gcloud. You only need to run this command once:
- Review and fill all the environment variables in
kubeflow-distribution/kubeflow/env.sh
, they will be used bykpt
later on, and some of them will be used in this deployment guide.
Review the comment in env.sh
for the explanation for each environment variable.
After defining these environment variables, run:
kpt setter config
Run the following commands to configure kpt setter for your Kubeflow cluster:
Everytime you change environment variables, make sure you run the command above to apply kpt setter change to all packages. Otherwise, kustomize build will not be able to pick up new changes.
Note, you can find out which setters exist in a package and their current values by running the following commands:
You can learn more about list-setters
in kpt documentation.
Authorize Cloud Config Connector for each Kubeflow project
- Set the Management environment variable if you haven’t:
Apply ConfigConnectorContext for ${KF_PROJECT}
in management cluster:
make apply-kcc
Configure Kubeflow
Make sure you are using KF_PROJECT in the gcloud CLI tool:
Deploy Kubeflow
To deploy Kubeflow, run the following command:
Access the Kubeflow user interface (UI)
To access the Kubeflow central dashboard, follow these steps:
Use the following command to grant yourself the IAP-secured Web App User role:
Enter the following URI into your browser address bar. It can take 20 minutes for the URI to become available: https://${KF_NAME}.endpoints.${KF_PROJECT}.cloud.goog/
Kubeflow dashboard is now available at the following URL: https://${KF_NAME}.endpoints.${KF_PROJECT}.cloud.goog/
Setting up Kubeflow
Now we have set up both the management and kubeflow cluster, we can start exploring and using the kubeflow dashboard.
Set up Notebook instance
GitHub Connection
To integrate with GitHub, you need to create a GitHub token and we will use it when cloning the repo in the notebook instance.
First we will need to install the pexpect
package in the notebook instance.
Now we are all set, we can start building ML pipelines with Kubeflow!
Building ML Pipelines with Kubeflow
When working with notebooks in Kubeflow, you can use the Kubeflow Pipelines SDK to create reusable components and pipelines. The SDK allows you to define a pipeline using Python code, which can be executed in a Jupyter notebook or a Python script. The SDK provides a set of high-level abstractions that make it easy to define and run pipelines in Kubeflow.
In this section, we will walk through the process of building a machine learning pipeline using the Kubeflow Pipelines SDK. We will start by building the pipelines on Vertex AI and then move on to deploy the pipelines on Kubeflow.
Building Vertex AI ML Pipelines with Kubeflow
To begin using the Kubeflow Pipelines SDK, you need to install the most recent version of protobuf then install the version 3.20.x
Building kubeflow ML Pipelines with Kubeflow
Now, since we already have a running kubeflow pipeline, to deploy it to the kubeflow cluster, we can use the following command:
After the execution of the above command, you can see the pipeline appear on the kubeflow UI under the Pipelines
tab.
Once you have a running pipeline, on the kubeflow UI, we can also Create Experiment
and Create Runs
etc. as well.
Deploying ML Endpoints with Kubeflow
Similar to building ML pipelines, you can deploy ML endpoints, both Vertex AI model registry and kubeflow endpoint with Kubeflow SDK.
In this section, we will walk through the process of deploying ML endpoints on Vertex AI and Kubeflow.
Deploying Vertex AI endpoints with kubeflow for predictions
After the above command executed successfully, you can see the endpoint deployed on Vertex AI on the Vertex AI UI under Online Predictions
> Endpoints
Deploying Kubeflow endpoints with Kubeflow for predictions
After the above command executed successfully, you can see the endpoint deployed on Kubeflow on the Kubeflow UI under Endpoints
Making predictions with Vertex AI Endpoints
Making predictions with Kubeflow Endpoints
Using MLFlow with Kubeflow
Within the Kubeflow Notebook, you can also use MLFlow to track and manage your machine learning experiments.
In the below example, I am using the wine data to train a XGBoost model and track the experiment with MLFlow.
And that’s it, now you have a running kubeflow application for your MLOps workload with MLFlow integration.
Thank you for reading and have a nice day!