Deploying a Python app - Part 2 (Kubernetes)
In Part 1 of this tutorial, we deployed a simple Flask app using docker. In this part, we'll deploy that same app using Kubernetes.
apiVersion: apps/v1
kind: Deployment
metadata:
name: trains
spec:
selector:
matchLabels:
app: trains
replicas: 2
template:
metadata:
labels:
app: trains
spec:
containers:
- name: trains
image: slemasne/trains:latest
resources:
limits:
memory: "100Mi"
requests:
memory: "50Mi"
ports:
- containerPort: 5000
kubectl port-forward deployment/trains 5000:5000
We check the pod is online by running a curl command.
$ curl -I http://127.0.0.1:5000/
This command returns a status code of 200:
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 21
Server: Werkzeug/1.0.1 Python/3.7.9
Date: Wed, 14 Sep 2022 18:01:56 GMT