How to Deploy MLflow on the Vultr Kubernetes Engine
Published: 2024-02-23 13:28:26

---
title: How to Deploy MLflow on the Vultr Kubernetes Engine
published: true
date: 2023-11-12 00:00:00 UTC
tags: 
canonical_url: https://lukicdejan.com/how-to-deploy-mlflow-on-the-vultr-kubernetes-engine/
---

_Originally written for Vultr_

## Introduction

MLflow is a versatile open-source Machine Learning (ML) platform for model lifecycle management. It supports experimentation, duplicability, deployment, and a central model registry. MLflow is used to track machine learning workload experiments, packaging and deployment of code, and collaborative management. Frequently used by data scientists and by MLOps professionals.

This article explains how to deploy MLflow on a Vultr Kubernetes Engine (VKE) cluster with a working environment and demo application.

## Prerequisites

Before you begin:

- Deploy a [Vultr Kubernetes Engine (VKE) cluster](https://www.vultr.com/docs/vultr-kubernetes-engine/)

- Deploy a [Vultr Ubuntu instance](http://vultr.com/servers/ubuntu) to use as your management server

- Using [SSH](https://www.vultr.com/docs/how-to-use-ssh-with-vultr-servers/), access the server

- [Install and configure Kubectl](https://www.vultr.com/docs/beginners-guide-to-kubernetes-using-kubectl/) to access the cluster

- Install the Helm package manager

## Deploy Persistent Volume and Persistent Volume Claims (PVCs)

MLflow requires persistent storage to store artifacts and experiment data. In this section, deploy a PV and PVC to the cluster as described in the steps below.

1. Create a new file `mlflow-pv-pvc.yaml`

2. Using a text editor such as `nano`, edit the file

3. Add the following contents to the file

4. Apply the configuration to your cluster

5. Verify the deployed Cluster PVs

## Install MLflow 

1. Using Helm, add `community-charts` to your repositories

2. Update the Helm repository index

3. Install MLflow. Replace `vultr`` with your desired MLflow label

4. View the cluster deployment to verify that MLflow is ready and available

## Expose the MLflow Forwarding Service For External Access

To access your MLflow deployment over the Internet, set up a forwarding service to expose the application for external access as described in the steps below.

1. Create a new file `mlflow-service.yaml`

2. Edit the file

3. Add the following contents to the file

4. Apply the service to your cluster

Wait for at least 3 minutes, view the cluster services, and verify the MLflow **External IP** value

```
    $ kubectl get services

Your output should look like the one below:

    NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

    kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 40m

    mlflow-service LoadBalancer 10.110.234.98 192.0.2.100 80:31545/TCP 64s

    vultr-mlflow ClusterIP 10.102.93.29 <none> 5000/TCP 101s

```

## Create a sample Mlflow Experiment

To test the Mlflow functionalities, create a sample linear regression experiment as described in the steps below.

1. Create a new directory `Models`

2. Switch to the directory

3. Using `pip``, install the necessary experiment dependencies

4. Create a new environment variable with your desired experiment name

5. Export a new `MLFLOW_TRACKING_URI` with your MLflow service external IP HTTP URL as the value. For example `192.0.2.100`

6. Create a new file `main.py`

7. Edit the file

8. Add the following contents to the file

The above Python application imports all necessary libraries and uses the diabetes dataset for training data. The dataset contains a total of 442 samples. Then, the model is trained and an explanation is logged to MLflow using SHAP (Shapley Additive Explanations) that plots the output for a visual representation of the data.

## Test the MLflow Experiement

1. Run the Python application

2. Using a web browser such as Chrome, visit your MLflow external IP address

Verify that the application is included in your MLflow experiments. It uses a linear regression statistical approach to model a relationship between a scalar response and one or more variables.

![MLflow UI showing the diabetes linear regression experiment](https://www.vultr.com/vultr-docs-graphics/8018/ydxlF2U.png)

## Conclusion

You have deployed MLflow on a Vultr Kubernetes Engine (VKE) cluster. To test the service operations, implement more examples from the [MLflow repository](https://mlflow.org/docs/latest/tutorials-and-examples/index.html). For more information about MLflow, visit the following documentation resources:

- [Mlflow documentation](https://mlflow.org/docs/latest/index.html)
- [Mlflow Recipes](https://mlflow.org/docs/latest/recipes.html#recipes)
- [MLflow Projects](https://mlflow.org/docs/latest/projects.html#projects)

## Next Steps

To implement more solutions, visit the following resources:

- [Deploy a Machine Learning Model to Production with TensorFlow Serving](https://www.vultr.com/docs/deploy-a-machine-learning-model-to-production-with-tensorflow-serving/)
- [How to Build a Machine Learning Classifier in Python with Scikit Learn](https://www.vultr.com/docs/how-to-build-a-machine-learning-classifier-in-python-with-scikit-learn/)
- [Introduction to Vultr Talon Cloud GPUs](https://www.vultr.com/docs/introduction-to-vultr-talon-cloud-gpus/)
- [Fine Tune a Hugging Face Diffuser Model on Vultr Cloud GPU](https://www.vultr.com/docs/fine-tune-a-hugging-face-diffuser-model-on-vultr-cloud-gpu/)