This project demonstrates a simple approach to deploying machine learning models in a Docker container using Kubernetes Helm charts. It aims to provide a scalable and manageable solution for deploying machine learning models within a Kubernetes cluster.
- Docker installed on your local machine
- Kubernetes cluster set up
- Helm installed on your local machine
- Basic understanding of Docker, Kubernetes, and Helm
-
Clone the Repository:
git clone https://github.com/subhayukumar/auto-deploy-ml-api.git
-
Copy the
helmchart andDockerfilefiles to your project.cp -r auto-deploy-ml-api/helm [/path/to/your/project] cp -r auto-deploy-ml-api/Dockerfile [/path/to/your/project] cd [/path/to/your/project] -
Edit the Dockerfile to work with your environment app
-
Build and Tag the Docker Image:
docker build -t [your-image-name] . docker tag [your-image-name]:[your-tag] [your-username]/[your-image-name]:[your-tag] -
Push the Docker Image to a Container Registry:
docker push [your-username]/[your-image-name]:[your-tag] # pushes the image to dockerhub -
Deploy the Helm Chart:
helm install [release-name] ./helm --set service.port=8000 --set image.repository=[your-username]/[your-image-name] --set image.tag=[your-tag]
-
Access the API: Run the below command by replacing
[release-name]with the name of your Helm release to get the URL of the deployed API:kubectl get service -l name=ml-app -l release=[release-name] -o=jsonpath='http://{.items[0].status.loadBalancer.ingress[0].ip}:{.items[0].spec.ports[0].port}/ '
If you have a pre-trained machine learning model hosted externally, you can configure the project to use this external model. Follow the steps below to incorporate the external model into the deployment:
- Update the
MODEL_URLenvironment variable:- Open the
values.yamlfile in the Helm chart directory. - Modify the
modelUrlfield to include the URL of your externally hosted model. - Redeploy the Helm chart using the
helm upgradecommand.
- Open the
By following these steps, you can seamlessly integrate an externally hosted machine learning model into the Dockerized deployment using Helm.
To run the Helm chart with custom values, you can use the --set flag with the helm install or helm upgrade command. Here's an example of how to deploy the Helm chart with custom values:
helm install [myapp-release] ./myapp-chart --set modelUrl=[your-model-url]Ensure that you replace the placeholders your-model-url with the URL of your externally hosted model. You can modify other parameters as necessary according to your use case.
You can customize the deployment further by adjusting other parameters available in the values.yaml file in the Helm chart directory.
Dockerfile: Contains the basic structure for the ML model deployment. [For demo purposes only. Use your own Dockerfile instead.]api.py: Includes the code for the API endpoint that serves the machine learning model. [For demo purposes only. Use your own code instead.]requirements.txt: Contains the dependencies for running theapi.py.helm: Contains the Helm chart for deploying the Dockerized ML model.values.yaml: Contains the configuration for the Helm chart.Chart.yaml: Contains the metadata for the Helm chart.templates: Contains the templates for the Helm chart.deployment.yaml: Contains the deployment specification for the Helm chart.service.yaml: Contains the service specification for the Helm chart._helpers.tpl: Contains the helper functions for the Helm chart.