This project aims at operationalize a Machine Learning Microservice API.
A pre-trained, sklearn model that has been trained to predict housing prices in Boston according to several features, such as average rooms in a home and data about highway access, teacher-to-pupil ratios, and so on is used in this project. You can read more about the data, which was initially taken from Kaggle, on the data source site. This project could be extended to any pre-trained machine learning model, such as those for image recognition and data labeling.
Operationalize machine learning microservice using kubernetes, which is an open-source system for automating the management of containerized applications.
- Circleci for CI/CD
- Build and run a docker image of prediction-app
- Upload prediction-app container to docker hub
- Deploy the container using Kubernetes and make a prediction
.circleci
contains pipeline scriptmodel_data/housing.csv
contains sample data to predict fromapp.py
prediction programrequirements.txt
contains application dependenciesoutput_txt_files
contains sample of app running logs
- Python 3.7 is required
- Hadolint
- kubernetes
- minikube
- Create docker account
- Edit dockerpath in
upload_docker.sh
andrun_kubernetes.sh
- Create a virtualenv with Python 3.7 and activate it. Refer to this link for help on specifying the Python version in the virtualenv.
python3 -m pip install --user virtualenv
# You should have Python 3.7 available in your host.
# Check the Python path using `which python3`
# Use a command similar to this one:
python3 -m virtualenv --python=<path-to-Python3.7> .devops
source .devops/bin/activate
$ cd microservice-kubernetes/
# Run make setup to create virtualenv and activate it
$ make setup
# Run make install to install the necessary dependencies
$ make install
# Run make lint to check python script and dockerfile
$ make lint
### Build container and run
```bash
# Build and run
$ ./run_docker.sh
# Make a prediction
$ ./make_predicton.sh
$ ./upload_docker.sh
# Start a cluster
$ minicube start
# Run container in kubernetes (run script again after pod creation)
$ ./run_kubernetes
# Check pod status
$ kubectl get pods prediction-app
# Make a prediction (be sure web app is running on port 8000)
$ ./make_predicton.sh
# Delete the pod
$ kubectl delete pods prediction-app
# Stop the cluster and delete
$ minicube stop && minicube delete