Tune from measurements. After 300 requests, the containers' cgroup files (kubectl 5,150 exec <pod> -- cat /sys/fs/cgroup/memory.peak) read about 26 MiB per API Pod, 37 MiB for PostgreSQL 1,289 and 8 MiB for Nginx 75 . So PostgreSQL gets a 100m CPU request and 256 MiB as request and limit (room for its shared buffers), Nginx 10m and 16 MiB with a 64 MiB limit, and the API a startup probe and three-second timeouts, since /ready makes a database round trip:
startupProbe:
httpGet: { path: /health, port: http }
periodSeconds: 2
failureThreshold: 30 # up to 60 s to connect, create the schema and listen
readinessProbe:
httpGet: { path: /ready, port: http }
periodSeconds: 5
timeoutSeconds: 3
livenessProbe: { httpGet: { path: /health, port: http }, timeoutSeconds: 3 }kubectl apply -f k8s/postgres.yaml -f k8s/web.yaml | grep -v unchanged
kubectl rollout status sts/postgres >/dev/null && kubectl rollout status deploy/web >/dev/null
kubectl apply -f k8s/api-deployment.yaml && kubectl rollout status deploy/api >/dev/null
sleep 5; kubectl get pods -l app=booknest \
-o jsonpath='{range .items[*]}{.status.qosClass}{"\n"}{end}' | sort | uniq -c
git commit -qam "Tune the API's probes and give PostgreSQL and the front end resources"Output
statefulset.apps/postgres configured
deployment.apps/web configured
deployment.apps/api configured
6 BurstableAll six Pods are now Burstable; no CPU limit anywhere is deliberate. Autoscaling Pods and Nodes turns the API's CPU request into the yardstick for autoscaling.