MLFlow is a platform that simplifies the end-to-end machine learning lifecycle, aiding in experiment tracking, reproducibility, and deployment. Deploying MLFlow on Kubernetes allows you to efficiently manage and deploy machine learning models at scale. This article explains how to deploy MLFlow on Kubernetes.
Prerequisites
Before you start:
- Access an Ubuntu server via SSH as a non-root user with sudo privileges to manage the cluster.
- Install and Configure Kubectl.
- Install the Helm package manager with the following command:
$ sudo snap install helm --classic
Installing Minikube
To install Minikube and start a Kubernetes cluster, follow these steps:
Step 1. Download the Latest Minikube Binary: Use curl
to download the latest Minikube binary from the official repository.
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Step 2. Install the Latest Minikube Binary: After downloading the binary, use the install
command to install Minikube to your system.
$ sudo install minikube-linux-amd64 /usr/local/bin/minikube
Step 3. Start the Kubernetes cluster: Once Minikube is installed, start the Kubernetes cluster using the minikube start
command. Specify the memory and CPU resources for the cluster as needed.
$ minikube start --memory=8096 --cpus=4
[Optional] If you don’t have a driver to allow minikube to function, you can use Docker. Use the following steps:
First download the Docker script “get-docker.sh” using curl and save it locally. Then execute the download script with root privileges using sudo to install Docker.
low these steps to set up Helm for MLflow:
Step 1. Create a new user named “test_mlfok”.
Setting MLflow on Kubernetes
Helm charts simplify and automate the deployment of MLflow on Kubernetes.
$ sudo adduser test_mlfok
Step 2. Add the user to the “docker” group to grant Docker privileges.
$ sudo usermod -aG docker test_mlfok
Step 3. Add the user to the “sudo” group to grant administrative privileges.
$ usermod -aG sudo test_mlfok
Step 4. Switch to the newly created user account.
$ su - test_mlfok
Step 5. Add Repository: Once Helm is installed, add the Helm repository for MLflow to your system. Visit Artifact Hub, a repository for Kubernetes packages, and search for ‘mlflow’. Then, add the repository.
$ helm repo add community-charts https://community-charts.github.io/helm-charts
Step 6. Install Chart: Install the MLflow chart using Helm.
$ helm install my-mlflow community-charts/mlflow --version 0.7.19
Step 7. Wait for Pod Initialization: After installation, wait for all Kubernetes pods to transition into the ‘Running’ state.
Step 8. Get Application URL: Retrieve the application URL by running the following commands:
$ export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mlflow,app.kubernetes.io/instance=my-mlflow" -o jsonpath="{.items[0].metadata.name}")
$ export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
Step 9. Port Forwarding: Use port forwarding to access the MLflow dashboard web interface.
$ kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
Step 10. Access MLflow Dashboard: Open your web browser and enter the address http://127.0.0.1:8080 to access the MLflow web UI. You have successfully deployed MLflow on Kubernetes and can now manage your machine learning experiments and models.
Conclusion
You’ve successfully deployed MLFlow on Kubernetes, using Helm charts for simplified management. With MLFlow running on Kubernetes, you can now gain access to powerful experiment tracking, model packaging, and deployment capabilities in a scalable and reliable environment. You can now efficiently manage your machine learning experiments and models, enhancing productivity and reproducibility in your workflow.
For further exploration and detailed documentation on MLFlow, visit the official documentation.