Configure Health Probes and Graceful Shutdown for a Kubernetes Deployment
Scenario
A deployment was shipped without health probes or graceful shutdown configuration. Without these, Kubernetes has no way to know:
- When the app has finished initialising and is ready to serve traffic
- Whether the process is still alive or has hung
- How to drain in-flight requests before killing the container
The deployment manifest is at /home/laborant/payment-deploy.yaml on
dev-machine.
The app already exposes the correct health endpoints — you only need to configure Kubernetes to use them.
Task
Edit /home/laborant/payment-deploy.yaml and add the following, then
reapply the manifest.
1. Startup Probe
Path /health/startup, port http. Set failureThreshold: 6 and
periodSeconds: 5.
2. Liveness Probe
Path /health/live, port http. Set initialDelaySeconds: 5,
periodSeconds: 10, failureThreshold: 3 — restarts the container
if the process hangs or deadlocks.
3. Readiness Probe
Path /health/ready, port http. Set initialDelaySeconds: 5,
periodSeconds: 5, failureThreshold: 3, successThreshold: 1 —
removes the pod from Service endpoints until it is fully ready, and
again during graceful shutdown.
4. preStop Hook and terminationGracePeriodSeconds
Configure a preStop httpGet hook on path /shutdown, port http.
Set terminationGracePeriodSeconds: 60 on the pod spec — Kubernetes
calls the preStop hook first, then sends SIGTERM, then waits up to
terminationGracePeriodSeconds before force-killing the container.
Once updated, apply the manifest and wait for the rollout to complete.
5. Capture logs
After the rollout, capture deployment logs containing the startup sequence and all three probe endpoints to :
/home/laborant/payment-logs.txt
Hint 1 — Where Each Field Goes in the Deployment
terminationGracePeriodSeconds is a pod-level field — it goes under
spec.template.spec, the same level as containers:
spec:
terminationGracePeriodSeconds: 60
containers:
- name: payment-api
All three probes and the lifecycle hook go inside the container spec,
the same level as image and ports:
- name: payment-api
startupProbe: { ... }
livenessProbe: { ... }
readinessProbe: { ... }
lifecycle:
preStop: { ... }
Documentation
Hint 2 — Probe Structure and the preStop Hook
All three probes use httpGet. The general structure is:
startupProbe:
httpGet:
path: /health/startup
port: http
failureThreshold: 6
periodSeconds: 5
The preStop hook uses the same httpGet format under lifecycle:
lifecycle:
preStop:
httpGet:
path: /shutdown
port: http
Documentation
Hint 3 — Apply and Capture Logs
After editing the manifest, apply it and wait for the rollout:
kubectl apply -f /home/laborant/payment-deploy.yaml
kubectl rollout status deployment/payment-api -n payment
Capture logs from the deployment:
kubectl logs deployments/payment-api payment-api \
-n payment > /home/laborant/payment-logs.txt
Documentation