Add a Liveness Probe#

In order to best maintain your pods, Kubernetes needs to know if a pod is alive or not. A liveness probe is an action that the Kubernetes system takes periodically to determine if a pod is working.


You can see examples of liveness probes in the Kubernetes documentation.

Configure Django#

Django comes with a security measure that prevents the liveness probe from working. Add the following line to mysite/ to defeat the allowed hosts protection, which is not needed when the app is running in Kubernetes:


Rebuild the Container!

This change requires that you rebuild the container. You should commit the change to GitHub and wait for the new container to build.

The Liveness Probe#

Since Django is a web application we can use a simple form of liveness probe: Having Kubernetes fetch a URL in our application. The configuration fragment shows how to configure the probe.

Add this to the container definition in deployment/mysite-pod.yaml:

    path: /polls/
    port: 8000