Cheat SheetsKubernetesProduction

Production — Cheat Sheet

Kubernetes · 1 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Production
Kubernetes1 topicsQuick revision reference
1

Production Patterns — Probes, Affinity & Pod Disruption

Production Kubernetes requires readiness/liveness/startup probes, pod affinity and anti-affinity rules for HA placement, Pod Disruption Budgets for safe maintenance, and resource quotas for cluster stability.

  • startupProbe gives slow apps time to initialise without triggering liveness restarts.
  • readinessProbe removes pods from Service endpoints — use for dependency health, not liveness.
  • livenessProbe should only restart the pod if the process is genuinely stuck — not for DB down.
  • Pod anti-affinity + topologySpreadConstraints spread pods across nodes and AZs for HA.
  • PDBs prevent cluster maintenance from taking your service below its availability SLA.
  • Aggressive liveness probes under load cause restart loops — set failureThreshold conservatively.
Kubernetes probe configuration and anti-patterns
spec:

  containers:

    - name: app

      image: my-app:v1.2.3



      # startupProbe: gives slow-starting containers time to init

      # Checked every periodSeconds, up to failureThreshold times

      # Total grace: 30s * 10 = 5 minutes max startup time

      # ONLY checked during startup; disables liveness until it succeeds

      startupProbe:

        httpGet:

          path: /health/startup   # a fast endpoint that returns 200 when ready to start

          port: 8080

        failureThreshold: 30      # 30 * 10s = 5 minutes max

        periodSeconds: 10



      # readinessProbe: controls TRAFFIC routing (not restart)

      # If failing: removed from Service endpoints (no traffic)

      # If passing: added to Service endpoints (gets traffic)

      # ⚠️ Use for: dependency checks (DB connected?), circuit breaker open?

      readinessProbe:

        httpGet:

          path: /health/ready

          port: 8080

        initialDelaySeconds: 0     # startupProbe covers startup

        periodSeconds: 10

        failureThreshold: 3        # 3 failures = removed from endpoints

        successThreshold: 1        # 1 success = back in rotation



      # livenessProbe: triggers RESTART if failing

      # ⚠️ Be conservative — aggressive liveness = restart loops under load

      # Should ONLY fail if the process is genuinely stuck

      livenessProbe:

        httpGet:

          path: /health/live

          port: 8080

        periodSeconds: 15

        failureThreshold: 3        # 45 seconds to trigger restart

        timeoutSeconds: 5



# Common mistake: liveness probe checking DB connectivity

# If DB is down, liveness restarts ALL pods → more load on recovering DB → cascade failure

# Readiness: check DB (remove from traffic)

# Liveness:  only check if process is stuck (not external deps)
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/kubernetes