Archive · Kubernetes

Health Probes and Resource Requests

Tell Kubernetes when a pod is ready and how much CPU and memory it needs.

1 min read

  • Kubernetes 1.21

Without probes Kubernetes only knows a process is running, not that it works.

containers:
  - name: api
    image: myapi:1.0
    readinessProbe:
      httpGet: { path: /ready, port: 8080 }
      periodSeconds: 5
    livenessProbe:
      httpGet: { path: /health, port: 8080 }
      initialDelaySeconds: 20
      periodSeconds: 10
    resources:
      requests: { cpu: 250m, memory: 256Mi }
      limits:   { memory: 512Mi }
  • Readiness failing removes the pod from service endpoints.
  • Liveness failing restarts the container. Keep it cheap, and do not check dependencies in it.
  • Requests drive scheduling. Limits are enforced: exceeding the memory limit gives OOMKilled; CPU over the limit is throttled.

Always set memory requests. Many teams leave CPU limits unset to avoid throttling. For slow-starting apps use a startupProbe (stable since 1.20) so liveness does not kill them during start.