pip install mlflow fastapi uvicorn streamlit
python ex_1_model_building.py
View the Models using MLFlow UI:
cd /ml-deployment/mflow-examples$ mlflow ui
mlflow ui
mlflow server --host 0.0.0.0
Start the FastAPI server
uvicorn ex_2_model_serving_with_fastapi:app --reload
Test:
curl -X POST "http://127.0.0.1:8000/predict/" -H "accept: application/json" -H "Content-Type: application/json" -d '{"feature1": 5.1, "feature2": 3.5, "feature3": 1.4, "feature4": 0.2}'
streamlit run app.py
- Build the image for the FastAPI server
docker build -t fastapi-model-server:v1.0 .
- Verify the Image
docker images
- Run the container
docker run -p 8000:8000 fastapi-model-server:v1.0
And test with the same curl command as above.
- Build the image for the Streamlit app
cd streamlit-app
docker build -t streamlit-app:v1.0 .
- Docker Compose
docker-compose up
TODO: fix the file path in docker-compose.yml for the streamlit app and FastAPI server.
- Create an EKS cluster
eksctl create cluster --name ex-eks-cluster --region ap-southeast-2
A cost-effective cluster can be created with the following command:
eksctl create cluster \
--name ex-eks-cluster \
--region ap-southeast-2 \
--node-type t3.micro \
--nodes-min 1 \
--nodes-max 1 \
--managed
- List the nodes
eksctl get nodegroup --cluster ex-eks-cluster
- Delete the cluster
eksctl delete cluster --name ex-eks-cluster --region ap-southeast-2
- Deploy (TODO)
### Deploy to Kubernetes (Minikube)
- [Install Minikube](https://www.baeldung.com/ops/minikube-getting-started)
```commandline
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- Start Minikube
sudo usermod -aG docker $USER && newgrp docker
minikube start
- Show the nodes
kubectl get nodes
Output:
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 30m v1.28.3
- Deploying an Application - FastAPI
```commandline
cd mlflow-examples
eval $(minikube docker-env)
docker build -t fastapi-model-server:v1.0 .
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
fastapi-model-server v1.0 1ced82f99552 4 seconds ago 1.79GB
Apply the configuration:
kubectl apply -f fastapi-deployment.yaml
kubectl get pods
output:
NAME READY STATUS RESTARTS AGE
fastapi-deployment-5f447f59d9-5ntxt 1/1 Running 0 57m
Access the service by url:
cd deployment
minikube service fastapi-service --url
output:
http://192.168.49.2:30129
Request using the url:
curl -X POST "http://123.456.789.1:30879/predict/" -H "accept: application/json" -H "Content-Type: application/json" -d '{"feature1": 5.1, "feature2": 3.5, "feature3": 1.4, "feature4": 0.2}'
output:
{"prediction":0.0}
- Deploying an Application - Streamlit
cd streamlit-app
eval $(minikube docker-env)
docker build -t streamlit-app:v1.0 .
cd deployment
kubectl apply -f streamlit-deployment.yaml
kubectl apply -f streamlit-service.yaml
Access the service by url:
minikube service streamlit-service --url