Deploy to Kubernetes#

In class you have created the three fundamental components of an application:

  1. A pod definition to define your executable code, CPU and memory requests.

  2. A service definition to make your pod reachable on the network.

  3. A persistent volume claim to hold your precious user data.

To complete this milestone you have to make new definitions for the Postgres database. The Postgres database should have a pod, service and PVC definition alongside of the mysite-*.yaml definitions. The deployment directory should look like this:

$ tree deployment
deployment
├── mysite-pod.yaml
├── mysite-pvc.yaml
├── mysite-service.yaml
├── postgres-pod.yaml
├── postgres-pvc.yaml
└── postgres-service.yaml

Notes on the Postgres Pod#

Here are some tips to save you time getting Postgres running.

  1. Use the image: docker.io/postgres:14.2

  2. The Postgres container uses the following environment variables. Set them in your pod definition. You can find the full list of Postgres environment variables in the documentation.

    1. Set POSTGRES_DB to mysitedb

    2. Set POSTGRES_USER to mysiteuser

    3. Set POSTGRES_PASSWORD to mysitepassword

  3. Postrgres stores it’s data in /var/lib/postgresql. Be sure to mount a PersistentVolume into that location.

Updates for the Django Pod#

The pod definition for mysite you created in the Make a Pod and Service for Django lab used environment variables to select the SQLite database. That needs to be changed for this milestone to work. In deployment/mysite-pod.yaml update the pod to set the following environment variables:

  1. Set DB_ENGINE to postgres

  2. Set DB_NAME to the same thing as POSTGRES_DB

  3. Set DB_USER to the same thing as POSTGRES_USER

  4. Set DB_HOST to the name of the Postgres service in the file deployment/postgres-service.yaml

  5. Set DB_PASSWORD to the same thing as POSTGRES_PASSWORD

  6. Set DJANGO_ADMIN_EMAIL to test@test.test

  7. Set DJANGO_ADMIN_USERNAME to test

  8. Set DJANGO_SUPERUSER_PASSWORD to testtest

Requirements#

  1. A Pod definition for Django that includes:

    1. Reasonable resource requests

    2. A liveness probe that checks that Django is serving requests

  2. A Service definition for Django with type LoadBalancer

  3. A Pod definition for Postgres that includes:

    1. Reasonable resource requests

  4. A Service definition for Postgres with type ClusterIP

  5. A PersistentVolumeClaim for Postgres

Test Procedure#

When you submit the milestone I will check your code by trying to run the equivalent of the following commands in a cluster with nothing running and no volume claims:

$ kubectl apply -f deployment/postgres-pvc.yaml
$ kubectl apply -f deployment/postgres-pod.yaml
$ kubectl apply -f deployment/postgres-service.yaml
$ kubectl apply -f deployment/mysite-pod.yaml
$ kubectl apply -f deployment/mysite-service.yaml
$ kubectl port-forward service/mysite 8000:80 

I expect the default username to be test and password testtest.

Turn In#

A link to your GitHub repo.