Minikube Local Deployment
Deploy MLFlow and FastAPI locally using minikube for testing and development. Note that this infrastructure does NOT include all the components of the MLOps pipeline - it is limited to MLFlow and FastAPI and is meant for practice with Kubernetes before moving to the cloud. deployml only generates the manifest (which then may need to be edited) and then creates the deployment in minikube.
Overview
Minikube provides a local Kubernetes environment for testing and development. It's ideal for:
- Local testing
- No cloud costs
- Fast iteration
- Learning Kubernetes
Prerequisites
Install minikube following instructures here.
Example
deployml is only used for generating the manifest and then deploying in minikube. In order to deploy MLFlow and FastAPI in minikube, we will need to create the Docker images for both. The corresponding dockerfiles can be found here.
1. Initialize Minikube for MLflow
# Generate MLflow manifests
deployml mlflow-init \
--output-dir ./manifests/mlflow \
--image mlflow-demo:latest \
--backend-store-uri sqlite:///mlflow.db
# Deploy MLflow
deployml mlflow-deploy --manifest-dir ./manifests/mlflow
2. Initialize Minikube for FastAPI
# Generate FastAPI manifests
deployml minikube-init \
--output-dir ./manifests/fastapi \
--image fastapi-mlflow-demo:latest \
--mlflow-uri http://mlflow-service:5000
# Deploy FastAPI
deployml minikube-deploy --manifest-dir ./manifests/fastapi
3. Access Services
# Get service URLs
minikube service mlflow-service --url
minikube service fastapi-service --url
# Or open in browser
minikube service mlflow-service
minikube service fastapi-service
Two-Step Workflow
Step 1: Generate Manifests
# MLflow
deployml mlflow-init \
--output-dir ./manifests/mlflow \
--image mlflow-demo:latest \
--backend-store-uri sqlite:///mlflow.db
# FastAPI
deployml minikube-init \
--output-dir ./manifests/fastapi \
--image fastapi-mlflow-demo:latest \
--mlflow-uri http://mlflow-service:5000
Step 2: Edit Manifests (Optional)
# Edit deployment.yaml to adjust resources
nano ./manifests/mlflow/deployment.yaml
# Common edits:
# - Adjust CPU/memory requests/limits
# - Change replica count
# - Modify environment variables
Step 3: Deploy
# Deploy MLflow
deployml mlflow-deploy --manifest-dir ./manifests/mlflow
# Deploy FastAPI
deployml minikube-deploy --manifest-dir ./manifests/fastapi
Verify Deployment
# Check pods
kubectl get pods
# Check services
kubectl get svc
# View logs
kubectl logs -l app=mlflow --tail=50 -f
kubectl logs -l app=fastapi --tail=50 -f
Testing
# Get MLflow URL
MLFLOW_URL=$(minikube service mlflow-service --url)
# Test health endpoint
curl $MLFLOW_URL/health
# Get FastAPI URL
FASTAPI_URL=$(minikube service fastapi-service --url)
# Test health endpoint
curl $FASTAPI_URL/health
Cleanup
# Delete deployments
kubectl delete deployment mlflow-deployment fastapi-deployment
# Delete services
kubectl delete service mlflow-service fastapi-service
# Stop minikube
minikube stop
# Delete minikube cluster
minikube delete
Troubleshooting
Pod Not Starting
# Check pod status
kubectl get pods
kubectl describe pod POD_NAME
# Check logs
kubectl logs POD_NAME
Image Not Found
# Load image into minikube
minikube image load mlflow-demo:latest
minikube image load fastapi-mlflow-demo:latest
# Or use minikube's Docker daemon
eval $(minikube docker-env)
docker build -t mlflow-demo:latest .