In this project, you will operationalize a Machine Learning Microservice API.
This project tests your ability to operationalize a Python flask app—in a provided file, app.py—that serves out predictions (inference) about housing prices through API calls.
In this project you will:
- Test your project code using linting
- Deploy your containerized application using Docker and make a prediction
- Configure Kubernetes and create a Kubernetes cluster
- Deploy a container using Kubernetes and make a prediction
- Create a virtualenv,
.devops, with commandmake setupit runs the command below:
python3 -m virtualenv --python=<path-to-Python3.7> .devops- Activate the virtualenv,
.devops, with command:
source .devops/bin/activate- Run
make installto install the necessary dependencies in therequirements.txt& install hadolint using theMakefilecommands:
pip install --upgrade pip &&\
pip install -r requirements.txt
# Install hadolint
sudo wget -O /bin/hadolint https://github.com/hadolint/hadolint/releases/download/v1.16.3/hadolint-Linux-x86_64 &&\
sudo chmod +x /bin/hadolint- Install minikube using the commands:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube- (Optional) You can create a symbolic link to minikube’s binary named ‘kubectl’:
ln -s $(which minikube) /usr/local/bin/kubectl-
The
Dockerfilecreates a working_directory/app/, copies theapp.pyto/app/, exposes port80and sets up the CMD to runapp.pywith a python interpreter when the container runs. -
Run
make lintto lint theDockerfileandapp.py. -
Run
run_docker.shthat builds a docker image taggedpredictor, lists the docker images and runspredictorin a docker container. -
Run
make_prediction.shin a separate terminal to make the prediction. -
Run
upload_docker.shto tag and push the docker image created before to Docker Hub. You should change the variabledockerpathto your own account.
-
Start the minikube cluster using the command
minikube start. -
Run
run_kubernetes.shthat will deploy our docker image from docker hub to a minikube cluster, display the running pods and port forward port8000to80. -
Run
make_prediction.shin a separate terminal to make the prediction. -
(Optional) You can delete the cluster using
minikube deleteor stop the cluster usingminikube stopto conserve resources.