This is an exercise in containerizing a Python Flask web server. A CRUD RESTful API is implemented to manipulate data in a MongoDB database about passengers on the Titanic which can then be deployed to a Kubernetes cluster.
- The use of a manual nginx apparently to compensate the need for ingress is not necessary and hard to maintain
- The leftover commented out lines of the haproxy in the docker-compose file show lack of best practices (clean solution)
- Use of a deployment for the importer is not a good choice, it's not best practice to have a continually crash-looping pod reimporting the database all the time
- Minikube installed or
kubectl
configured for your Kubernetes cluster.
-
Clone this repo to a location of your choice.
-
cd
to this repo. -
Set up the cluster with the following command.
kubectl apply -f app-service.yaml,mongodb-service.yaml,app-deployment.yaml,mongo-seed-deployment.yaml,mongodb-deployment.yaml
-
Open the API site with
open $(minikube service app --url)/ui
If this were being run in AWS or Google Cloud, the ServiceType
of app
could be changed to LoadBalancer
automatically allocating an Ingress load balancer to the service. Otherwise to prevent the arbitrary port of 30000
from being exposed as a NodePort
an Ingress resource and Ingress controller could be created.
For the mongodb
database, a more complicated, but reliable storage structure could be implemented including creating a StorageClass
, Headless Service
, and a StatefulSet
to move the storage lifecycle from that of the Pod and to its own persistent resource.