Kubernetes – Simple Readiness and Liveness Probe, for Simple Nginx Deployments

multimeter

Liveness and Readiness

When deploying an Nginx pod for the sake of making some files available on the internet (because why use S3 or Minio, keep it simple… and private). Standard procedure with Kubernetes deployments is to have a liveness and readiness endpoint. This can be done with some Nginx configuration, or better yet, a file served from nginx root.

Connectivity and RO-filesystem

Assuming that the files to be served reside are in the Nginx Root (/usr/share/nginx/html), under a file-directory (lets say /files), all that is needed is a file containing the text “OK” or any other text in that same directory.

Create the OK file and copy it over to the served directory in the pod.

echo OK > OK
kubectl cp OK nginx-deployment-aoeuaoeu-auaoe:/files

Once copied over, the liveness and readiness probe can be added to the deployment.

livenessProbe:
  failureThreshold: 3
  httpGet:
    path: /files/OK
    port: 80
    scheme: HTTP
  initialDelaySeconds: 15
  periodSeconds: 20
  successThreshold: 1
  timeoutSeconds: 1
readinessProbe:
  failureThreshold: 3
  httpGet:
    path: /files/OK
    port: 80
    scheme: HTTP
  initialDelaySeconds: 5
  periodSeconds: 10
  successThreshold: 1
  timeoutSeconds: 1

The OK file or similar ensures the following:

  • That the Nginx pod is serving the file and is responding with 200 OK.
  • That the mounted volume where the file resides is working correctly.

Keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *