Skip to content

https://killercoda.com/sachin/course/CKA/pod-issue-4

Probes (CKA) — Examples, Types, and Command Paths

Probes tell Kubernetes when to restart a container (liveness), when to receive traffic (readiness), and when to wait before probing (startup).

Types:

  • exec (run a command in the container)
  • httpGet (HTTP endpoint)
  • tcpSocket (TCP port check)
  • gRPC (Kubernetes 1.24+)

1) Exec Probes (Command Path)

Exec probes run inside the container. Use an absolute path when possible to avoid PATH issues.

yaml
livenessProbe:
  exec:
    command:
      - /bin/sh
      - -c
      - "pg_isready -U postgres"
  initialDelaySeconds: 10
  periodSeconds: 5

Tip (CKA): If the command exists but PATH is different, the probe fails. Use /bin/sh -c or absolute binary path like /usr/bin/psql.


2) HTTP GET Probes

yaml
readinessProbe:
  httpGet:
    path: /healthz
    port: 8080
    scheme: HTTP
  initialDelaySeconds: 5
  periodSeconds: 5

HTTPS example:

yaml
livenessProbe:
  httpGet:
    path: /healthz
    port: 8443
    scheme: HTTPS
  initialDelaySeconds: 10
  periodSeconds: 10

3) TCP Socket Probes

Checks if a TCP port is open.

yaml
livenessProbe:
  tcpSocket:
    port: 5432
  initialDelaySeconds: 30
  periodSeconds: 10

4) Startup Probes (Slow Boot Apps)

Startup probe disables liveness/readiness checks until it succeeds.

yaml
startupProbe:
  httpGet:
    path: /startup
    port: 8080
  failureThreshold: 30
  periodSeconds: 5

5) gRPC Probes (Kubernetes 1.24+)

yaml
livenessProbe:
  grpc:
    port: 50051
  initialDelaySeconds: 5
  periodSeconds: 10

6) Full Example (Liveness + Readiness + Startup)

yaml
apiVersion: v1
kind: Pod
metadata:
  name: web-probe-demo
spec:
  containers:
    - name: web
      image: nginx:1.25
      ports:
        - containerPort: 80
      startupProbe:
        httpGet:
          path: /
          port: 80
        failureThreshold: 30
        periodSeconds: 5
      readinessProbe:
        httpGet:
          path: /
          port: 80
        initialDelaySeconds: 5
        periodSeconds: 5
      livenessProbe:
        httpGet:
          path: /
          port: 80
        initialDelaySeconds: 10
        periodSeconds: 10

7) Probe Tuning Knobs (CKA Quick Notes)

FieldWhat it controlsExample
initialDelaySecondsWait before first probe10
periodSecondsHow often to probe5
timeoutSecondsProbe timeout2
failureThresholdFailures before marking unhealthy3
successThresholdSuccesses before marking healthy1 (readiness can use >1)

8) Debugging Probes (Commands)

bash
# Describe Pod for probe failures
kubectl describe pod <pod>

# Check events
kubectl get events --sort-by=.metadata.creationTimestamp

# View container logs
kubectl logs <pod> -c <container>

# Test probe endpoint from within the pod
kubectl exec -it <pod> -- curl -s http://127.0.0.1:8080/healthz

# Check container port is listening
kubectl exec -it <pod> -- ss -ltnp

9) Common CKA Pitfalls

  • Exec probe fails because binary is not in PATH (use absolute path).
  • Readiness probe failing keeps Pod in NotReady (no Service traffic).
  • Liveness probe failing causes restarts.
  • Startup probe missing for slow apps causes false restarts.
  • Wrong port (containerPort ≠ Service port).

apiVersion: v1 kind: Pod metadata: name: postgres-pod spec: containers: - name: postgres image: postgres:latest env: - name: POSTGRES_PASSWORD value: dbpassword - name: POSTGRES_DB value: database ports: - containerPort: 5432 livenessProbe: tcpSocket: port: 5432 initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: exec: command: - psql - -h - localhost - -U - postgres - -c - SELECT 1 initialDelaySeconds: 5 periodSeconds: 5

Released under the MIT License.