Architecture
- Kubernetes (EKS)
- MLflow Tracking Server
- PostgreSQL database
- S3 bucket for artifacts
- LoadBalancer / Ingress for access
1. Create PostgreSQL Database
You can use:
- Amazon RDS PostgreSQL (Recommended)
- PostgreSQL inside Kubernetes
Recommended: Amazon Web Services RDS PostgreSQL.
Example DB details:
DB_HOST=mydb.xxxxxx.ap-south-1.rds.amazonaws.com
DB_NAME=mlflow
DB_USER=mlflow
DB_PASSWORD=password123
Create database:
CREATE DATABASE mlflow;
2. Create S3 Bucket for MLflow Artifacts
aws s3 mb s3://mlflow-artifacts-prod
Example artifact path:
s3://mlflow-artifacts-prod
3. Create IAM Role for EKS Service Account (IRSA)
MLflow needs access to S3.
Create IAM policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::mlflow-artifacts-prod",
"arn:aws:s3:::mlflow-artifacts-prod/*"
]
}
]
}
Attach policy to Kubernetes service account using IRSA.
4. Create Kubernetes Namespace
kubectl create namespace mlflow
5. Create Kubernetes Secret
kubectl create secret generic mlflow-secret \
--from-literal=DB_USER=mlflow \
--from-literal=DB_PASSWORD=password123 \
-n mlflow
6. MLflow Deployment YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: mlflow
namespace: mlflow
spec:
replicas: 1
selector:
matchLabels:
app: mlflow
template:
metadata:
labels:
app: mlflow
spec:
serviceAccountName: mlflow-sa
containers:
- name: mlflow
image: ghcr.io/mlflow/mlflow:v2.12.1
ports:
- containerPort: 5000
env:
- name: AWS_DEFAULT_REGION
value: ap-south-1
- name: MLFLOW_S3_ENDPOINT_URL
value: https://s3.amazonaws.com
- name: DB_USER
valueFrom:
secretKeyRef:
name: mlflow-secret
key: DB_USER
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: mlflow-secret
key: DB_PASSWORD
command:
- /bin/sh
- -c
args:
- |
pip install psycopg2-binary boto3 && \
mlflow server \
--backend-store-uri postgresql://$(DB_USER):$(DB_PASSWORD)@mydb.xxxxxx.ap-south-1.rds.amazonaws.com:5432/mlflow \
--default-artifact-root s3://mlflow-artifacts-prod \
--host 0.0.0.0 \
--port 5000
7. Service YAML
apiVersion: v1
kind: Service
metadata:
name: mlflow-service
namespace: mlflow
spec:
type: LoadBalancer
selector:
app: mlflow
ports:
- protocol: TCP
port: 80
targetPort: 5000
8. Deploy MLflow
kubectl apply -f mlflow-deployment.yaml
kubectl apply -f mlflow-service.yaml
Check:
kubectl get pods -n mlflow
kubectl get svc -n mlflow
9. Access MLflow
http://EXTERNAL-IP
You should see:
MLflow Tracking UI
10. Configure Client
Install MLflow locally:
pip install mlflow
Set tracking URI:
export MLFLOW_TRACKING_URI=http://EXTERNAL-IP
Test:
mlflow experiments list
Leave a Reply