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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With