This codebase contains all of the necessary files required to launch a simple Flask application on Digital Ocean Kubernetes (DOKs).
- DigitalOcean Container Registry (DOCR) is already created.
- DigitalOcean Kubernetes (DOKs) cluster is already provisioned.
- DOCR + DOks are already integrated.
Any environment variable configurations will be handled via python-dotenv or kubectl secrets.
Create a new directory in a location of your choice on your local machine and clone this repository into it.
git clone https://github.com/codyfishman/doks-resources/
Build the image locally with Docker.
docker build -t my-python-app .
Confirm the image is available in your local Docker registry.
docker images
Run the image locally with Docker.
docker run -ti -p 80:80 my-python-app
Run doctl’s login command for registries.
docker registry login
Tag your image locally with the DigitalOcean registry name.
docker tag my-python-app registry.digitalocean.com/<your-registry-name>/my-python-app
Push your image from the local Docker registry to the DigitalOcean registry.
docker push registry.digitalocean.com/<your-registry-name>/my-python-app
Deploy your application to your DOKs cluster by submitting a deployment object.
kubectl create deployment my-python-app --image=registry.digitalocean.com/<your-registry-name>/my-python-app
Check the replica set configuration.
kubectl get rs
Check the state of your pods (containers running your application).
kubectl get pods
Expose your application to the internet via a load balancer.
kubectl expose deployment my-python-app --type=LoadBalancer --port=80 --target-port=80
Confirm that the load balancer is activated.
doctl compute load-balancer list --format Name,Created,IP,Status
Confirm that the image exists on DOCR.
doctl registry repository list-tags <your-registry-name>/my-python-app
Check for warnings and error messages in the event log for a particular pod.
- You can get the pod name by running
kubectl get pods
and copying the name value listed for a degraded pod.
kubectl describe pod <pod_name>
Restart a deployment after fixes have been implemented.
kubectl rollout restart deployment my-python-app