MLflow With Wasabi

Prev Next

MLflow is an open-source platform for managing the machine learning lifecycle, including experiment tracking, model packaging, and a model registry. The MLflow tracking server stores run metadata, such as parameters and metrics, in a database and stores run artifacts, such as models, plots, and data files, in an artifact store. This article describes how to deploy an MLflow tracking server on a Kubernetes cluster and use a Wasabi bucket as the artifact store.

The tracking server in this article proxies artifact access to Wasabi, so MLflow clients need only the URL of the tracking server and do not need Wasabi access keys. Only the artifacts are stored in Wasabi. The run metadata is stored in a PostgreSQL database that you provide.

Requirements

This solution was tested with the software listed below. Later compatible versions are expected to work, but have not been specifically tested.

  • Active Wasabi Hot Cloud Storage account.

  • Access to the Wasabi Console as the account root user.

  • A Wasabi bucket. The bucket used in testing did not have Object Lock or Versioning enabled. For more information, review Working With Buckets and Objects.

  • A Kubernetes cluster with an ingress controller, and kubectl access to the cluster. The cluster used in this article was a single-node k3s v1.37.2+k3s1 cluster, which includes the Traefik ingress controller, running on Ubuntu Server 26.04.1 LTS. The MLflow pod in this article has a 4 GiB memory limit.

  • A fixed IP address (a static address or a DHCP reservation) for the server.

  • A PostgreSQL database that the cluster can reach, and the user name, password, and database name for MLflow to use. The user must be able to create tables in the database. The password must contain only letters and numbers. The tested version was PostgreSQL 16.15 (the postgres:16 container image), running in the mlflow namespace and reachable as the postgres service on port 5432. If your database is in a different namespace or outside the cluster, change the database address in the manifest, as described in Deploying MLflow.

  • MLflow 3.18.0 running in the python:3.12-slim container image. The psycopg2-binary, psycopg, and boto3 Python packages are installed without pinned versions. The tested versions were Python 3.12.16, psycopg2-binary 2.9.13, psycopg 3.3.8 (with psycopg-binary 3.3.8), and boto3 1.43.127.

  • A workstation with a web browser, macOS 26.7.1, Python 3.14.1, and the mlflow 3.18.0 Python package, to run a test script.

Configuring Wasabi

Reference commands in this article use placeholders such as YOUR_ARTIFACTS_BUCKET_NAME—replace them with your own values. Output labeled “Example output” was captured during testing using a bucket named mt-mlflow-artifacts and a server with the IP address 10.30.201.204. Where only part of the output is shown, the label says “excerpt”.

  1. Log in to the Wasabi Console as the account root user.

  2. Create a policy for an “mlflow” user (created in the next step) using the following policy. Change YOUR_ARTIFACTS_BUCKET_NAME to your own bucket name. See Creating a Policy for instructions.

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "AccountLevel",
          "Effect": "Allow",
          "Action": "s3:ListAllMyBuckets",
          "Resource": "arn:aws:s3:::*"
        },
        {
          "Sid": "BucketLevel",
          "Effect": "Allow",
          "Action": [
            "s3:ListBucket",
            "s3:ListBucketVersions"
          ],
          "Resource": "arn:aws:s3:::YOUR_ARTIFACTS_BUCKET_NAME"
        },
        {
          "Sid": "ObjectLevel",
          "Effect": "Allow",
          "Action": [
            "s3:GetObject",
            "s3:GetObjectVersion",
            "s3:PutObject",
            "s3:PutObjectTagging",
            "s3:DeleteObject",
            "s3:DeleteObjectVersion",
            "s3:AbortMultipartUpload",
            "s3:ListMultipartUploadParts"
          ],
          "Resource": "arn:aws:s3:::YOUR_ARTIFACTS_BUCKET_NAME/*"
        }
      ]
    }
  3. Create an “mlflow” user and attach the previously created policy to it. Use the following settings for the user. For more information, see Creating a User.

    • Allow programmatic-only access, not console access.

    • Do not require Multi-Factor Authentication (MFA).

    • It is not necessary to assign the user to a group.

    • Save the access and secret keys in a secure location.

Deploying MLflow

The following manifest runs the MLflow tracking server in a Python container. The server uses your PostgreSQL database as the backend store and the Wasabi bucket as the artifact store. Run the following commands on a computer that has kubectl access to your cluster.

  1. Store the values used in this article in shell variables. The commands prompt you for each value, so you do not need to edit any commands, and the keys and password are not saved in your shell history. The secret key and the password are not displayed as you type them. Enter the IP address and host name that browsers and scripts will use to reach MLflow, and the Wasabi bucket storage region.

    read -rp "MLflow IP address: " SERVER_IP
    read -rp "MLflow hostname: " SERVER_HOST
    read -rp "Wasabi storage region (for example, us-east-2): " WASABI_REGION
    read -rp "Artifacts bucket name: " ARTIFACTS_BUCKET
    read -rp "Wasabi access key: " WASABI_ACCESS_KEY
    read -rsp "Wasabi secret key: " WASABI_SECRET_KEY; echo
     
    read -rp "PostgreSQL user: " PG_USER
    read -rsp "PostgreSQL password (letters and numbers only): " PG_PASSWORD; echo
    read -rp "PostgreSQL database name: " PG_DB

    The variables exist only in the current terminal session. If you open a new terminal, run these commands again before you continue.

  2. Confirm that the variables are set. This command does not display the keys.

    echo "$ARTIFACTS_BUCKET $WASABI_REGION $SERVER_IP"
  3. Create the mlflow namespace and the Kubernetes secrets that hold the PostgreSQL and Wasabi credentials.  The secrets are always created in the mlflow namespace, even when the database is in another namespace.

    kubectl create namespace mlflow
     
    kubectl -n mlflow create secret generic postgres-creds \
      --from-literal=POSTGRES_USER="$PG_USER" \
      --from-literal=POSTGRES_PASSWORD="$PG_PASSWORD" \
      --from-literal=POSTGRES_DB="$PG_DB"
     
    kubectl -n mlflow create secret generic wasabi-creds \
      --from-literal=AWS_ACCESS_KEY_ID="$WASABI_ACCESS_KEY" \
      --from-literal=AWS_SECRET_ACCESS_KEY="$WASABI_SECRET_KEY"
     
    unset PG_PASSWORD

    If the mlflow namespace already exists, for example because PostgreSQL is deployed in it, the first command reports AlreadyExists. You can continue with the next command.

    Use a PostgreSQL password that contains only letters and numbers. MLflow builds a connection URL that includes the password, and characters such as @ in the password prevent MLflow from connecting.

  4. Create the MLflow manifest. The manifest assumes that PostgreSQL is reachable as postgres on port 5432 in the mlflow namespace. If your database is somewhere else, change postgres:5432 in the --backend-store-uri line before you continue. For a database service in another namespace, use the service’s full DNS name, postgres.YOUR_DB_NAMESPACE.svc.cluster.local:5432, with your own service name and namespace. For a database outside the cluster, use its host name or IP address and port. The namespace: mlflow settings in the manifest are for MLflow itself and do not change.

    cat > mlflow.yaml <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata: { name: mlflow, namespace: mlflow }
    spec:
      replicas: 1
      selector: { matchLabels: { app: mlflow } }
      template:
        metadata: { labels: { app: mlflow } }
        spec:
          containers:
            - name: mlflow
              image: python:3.12-slim
              command: ["/bin/sh", "-c"]
              args:
                - |
                  pip install --no-cache-dir mlflow==3.18.0 psycopg2-binary "psycopg[binary]" boto3 && \
                  mlflow server \
                    --host 0.0.0.0 --port 5000 \
                    --backend-store-uri "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}" \
                    --artifacts-destination s3://YOUR_ARTIFACTS_BUCKET_NAME/ \
                    --serve-artifacts \
                    --workers 2 \
                    --allowed-hosts "YOUR_SERVER_IP,YOUR_SERVER_HOSTNAME" \
                    --cors-allowed-origins "http://YOUR_SERVER_IP,http://YOUR_SERVER_HOSTNAME"
              envFrom:
                - secretRef: { name: wasabi-creds }
                - secretRef: { name: postgres-creds }
              env:
                - { name: MLFLOW_S3_ENDPOINT_URL, value: "https://s3.YOUR_WASABI_REGION.wasabisys.com" }
                - { name: AWS_DEFAULT_REGION, value: "YOUR_WASABI_REGION" }
              ports: [{ containerPort: 5000 }]
              readinessProbe:
                httpGet: { path: /health, port: 5000 }
                initialDelaySeconds: 60
                periodSeconds: 10
              resources:
                requests: { cpu: 200m, memory: 512Mi }
                limits: { memory: 4Gi }
    ---
    apiVersion: v1
    kind: Service
    metadata: { name: mlflow, namespace: mlflow }
    spec:
      selector: { app: mlflow }
      ports: [{ port: 5000, targetPort: 5000 }]
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata: { name: mlflow, namespace: mlflow }
    spec:
      rules:
        - http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service: { name: mlflow, port: { number: 5000 } }
    EOF
  5. Replace the placeholders with the values you entered earlier, and confirm that the values are correct.

    sed -i \
      -e "s|YOUR_ARTIFACTS_BUCKET_NAME|${ARTIFACTS_BUCKET}|g" \
      -e "s|YOUR_SERVER_IP|${SERVER_IP}|g" \
      -e "s|YOUR_SERVER_HOSTNAME|${SERVER_HOST}|g" \
      -e "s|YOUR_WASABI_REGION|${WASABI_REGION}|g" \
      mlflow.yaml
     
    grep -n -E "artifacts-destination|allowed-hosts|cors-allowed|MLFLOW_S3_ENDPOINT_URL" mlflow.yaml
  6. Deploy MLflow and wait for the mlflow pod to show 1/1 Running. Press Ctrl+C to stop watching. The pod installs its Python packages each time it starts, so it can take two to three minutes to become ready.

    kubectl apply -f mlflow.yaml
    kubectl -n mlflow get pods -w
  7. Open http://YOUR_SERVER_IP/ in a web browser on your workstation, replacing YOUR_SERVER_IP with the IP address of your MLflow server. MLflow 3.x shows a GenAI view and a Model training view. Click Model training to see experiments and runs. The manifest uses the following settings.

    • --serve-artifacts with --artifacts-destination makes the tracking server read and write artifacts in Wasabi on behalf of clients. Clients do not need Wasabi access keys.

    • --allowed-hosts and --cors-allowed-origins allow browsers to use the MLflow web interface at the server’s address. MLflow 3.x accepts only localhost by default and blocks other requests. The address in your browser and in your scripts must match one of the addresses in these settings, or MLflow returns an “Invalid Host header” error.

    • --workers 2 and the 4 GiB memory limit are the values used in testing. With a 2 GiB limit, the container was stopped for using too much memory.

    • The psycopg2-binary and psycopg[binary] packages are the PostgreSQL drivers that MLflow loads. Installing both avoids a missing-module error.

    • The ingress controller publishes the MLflow service on port 80 of the server.

      This manifest installs packages at startup to keep the example short. For a production deployment, build a container image that includes the packages. MLflow does not require authentication by default. See Security Considerations.

Testing MLflow With Wasabi

Log a test run from your workstation to confirm that run metadata is saved in PostgreSQL and the run’s artifact is saved in Wasabi.

  1. On your workstation, create a Python virtual environment and install MLflow. On Ubuntu and Debian, install the venv package first: sudo apt install python3-venv.

    python3 -m venv ~/mlflow-test
    source ~/mlflow-test/bin/activate
    python -m pip install mlflow
  2. Save the following script as test_run.py. Replace YOUR_SERVER_IP with the IP address of your server.

    import mlflow
     
    mlflow.set_tracking_uri("http://YOUR_SERVER_IP")
    mlflow.set_experiment("wasabi-test")
     
    with mlflow.start_run():
        mlflow.log_param("lr", 0.01)
        mlflow.log_metric("accuracy", 0.93)
        with open("notes.txt", "w") as f:
            f.write("hello wasabi")
        mlflow.log_artifact("notes.txt")
  3. Run the script.

    python test_run.py

    Example output:

    🏃 View run useful-deer-202 at: http://10.30.201.204/#/experiments/1/runs/d46006fab3dc4de4a7e58daed34543ac
    🧪 View experiment at: http://10.30.201.204/#/experiments/1
  4. In the MLflow web interface, click Model training.

  5. Click Experiments.

  6. Select the wasabi-test experiment.

  7. Click the name of the run. The red and green dots are just chart colors, and they don’t mean success or failure. The green check mark means the run finished.

  8. On the Overview tab, confirm that the accuracy metric (0.93) and the lr parameter (0.01) appear. The run’s ID is shown on this page.

  9. Select the Artifacts tab.

  10. Click notes.txt. MLflow reads the file through the tracking server, so the file contents shown here come from Wasabi.

  11. Log in to the Wasabi Console.

  12. Click Buckets, then click the name of the artifacts bucket.  

  13. Browse to the folder named for the experiment ID, then the folder named for the run ID, and then the artifacts folder. The notes.txt object is stored at <experiment-id>/<run-id>/artifacts/notes.txt. The run ID matches the one shown in MLflow.

Security Considerations

  • MLflow does not require authentication by default. Anyone who can reach the server can view and change experiments. Restrict network access to the server and enable MLflow authentication before you use this deployment for more than testing.

  • The Wasabi keys and the PostgreSQL password are stored in Kubernetes secrets in the mlflow namespace. Restrict access to the namespace.

  • Limit the Wasabi user’s policy to the bucket used in this article, as shown in Configuring Wasabi.

  • When you finish, remove the keys from your shell session.

    unset WASABI_ACCESS_KEY WASABI_SECRET_KEY