-
Open GKE terminal.
-
Start minikube in Google Cloud Platform
minikube start -
Create requirements.txt file using the following command:
nano requirements.txt
Enter the following contents in requirements.txt:
Flask==1.1.1
gunicorn==19.9.0
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
Werkzeug==0.15.5
numpy==1.19.5
scipy>=0.15.1
scikit-learn==0.24.2
matplotlib>=1.4.3
pandas>=0.19
flasgger==0.9.4
Upload logreg.pkl file which we got from ML.ipynb and using data set
-
Click the three dots in the top-right part of the Cloud Shell Terminal
-
Choose upload and upload the logreg.pkl file
-
Create flask_api.py file using the command:
nano flask_api.py
or, you can also uplaod it from flask_api.py file
-
Create Dockerfile using the command:
nano Dockerfile
Enter the following contents in Dockerfile:
FROM python:3.8-slim
WORKDIR /app
COPY . /app
EXPOSE 5000
RUN pip install -r requirements.txt
CMD ["python", "flask_api.py"]
-
Build the Docker image using the command:
sudo docker build -t ml_app_docker . -
Run the Docker container using the command:
docker container run -p 5000:5000 ml_app_docker -
Preview the application:
-
In the upper-right side of the terminal, click the eye-shaped button and then click "Preview on port 5000".
-
Add /apidocs/ at the end of the link to access the running ml-app.
- Make predictions for a group of customers (test data) via a POST request:
-
Upload the test data file containing the same parameters in a similar order.
-
Execute to display the results.
-
List running Docker containers using the command:
docker ps -
Use the command to kill the running container
docker kill <CONTAINER ID>
-
Log in to Docker Hub:
docker login -
Tag the Image:
docker tag ml_app_docker nazninnahar054/ml_docker:latest -
Push the Image:
docker push nazninnahar054/ml_docker:latest -
Verify the image exists locally by listing your Docker images:
docker images
P.S. Before login to docker build the image if pushing isn't working
Use the GKE we have created in Step 1
-
Create a deployment.yaml with the following contents.
nano deployment.yamlthen write this content
-
Create deployment with the above file.
kubectl apply -f ml-app-deployment.yaml -
Wait for couple minutes and list all the pods created
kubectl get deployments kubectl get pods -
Create a service.yaml
nano service.yaml
then write this content
-
Create service with the above file
kubectl apply -f ml-app-service.yaml -
Get service external ip
kubectl get services -
Access using browser:
external-ip/apidocs


