Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My k8s liveness probe isn't setting the Host

I'm trying to deploy a Django app with startup and liveness probes configured. As it's a Django app, I need the Host header on the probes to match something permitted in my ALLOWED_HOSTS. As my probes are both httpGet checks, the simplest solution seems like it would be to use the httpHeaders field as suggested in the kubernetes docs.

This seems to work for the startupProbe, however it's not working for the livenessProbe.

Sanitized version of my probes:

livenessProbe:
  httpGet:
    httpHeaders:
      - name: Host
        value: k8s-probes
    path: /health/liveness
    port: http
    scheme: HTTP
startupProbe:
  httpGet:
    httpHeaders:
      - name: Host
        value: k8s-probes
    path: /health/
    port: http
    scheme: HTTP

When the pod startups up, I see 200 responses to the initial startup probes, then once the liveness probe starts, I get 400 responses with the error that the pod IP address isn't in ALLOWED_HOSTS, indicating k8s isn't setting the Host header I've defined for the liveness probe.

like image 450
Endophage Avatar asked Oct 17 '25 19:10

Endophage


1 Answers

I've ended up using this configuration (thanks to @endophage for the hint)

ALLOWED_HOSTS = [
    os.environ['DJANGO_ALLOWED_HOSTS'],
    os.environ['POD_IP'],
]

and in the deployment:

env:
  - name: POD_IP
    valueFrom:
      fieldRef:
        fieldPath: status.podIP
readinessProbe:
  httpGet:
    path: /
    port: http

like image 149
reto Avatar answered Oct 19 '25 12:10

reto