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.
livenessProbe:
exec:
command:
- /bin/sh
- -c
- "pg_isready -U postgres"
initialDelaySeconds: 10
periodSeconds: 5Tip (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
readinessProbe:
httpGet:
path: /healthz
port: 8080
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 5HTTPS example:
livenessProbe:
httpGet:
path: /healthz
port: 8443
scheme: HTTPS
initialDelaySeconds: 10
periodSeconds: 103) TCP Socket Probes
Checks if a TCP port is open.
livenessProbe:
tcpSocket:
port: 5432
initialDelaySeconds: 30
periodSeconds: 104) Startup Probes (Slow Boot Apps)
Startup probe disables liveness/readiness checks until it succeeds.
startupProbe:
httpGet:
path: /startup
port: 8080
failureThreshold: 30
periodSeconds: 55) gRPC Probes (Kubernetes 1.24+)
livenessProbe:
grpc:
port: 50051
initialDelaySeconds: 5
periodSeconds: 106) Full Example (Liveness + Readiness + Startup)
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: 107) Probe Tuning Knobs (CKA Quick Notes)
| Field | What it controls | Example |
|---|---|---|
initialDelaySeconds | Wait before first probe | 10 |
periodSeconds | How often to probe | 5 |
timeoutSeconds | Probe timeout | 2 |
failureThreshold | Failures before marking unhealthy | 3 |
successThreshold | Successes before marking healthy | 1 (readiness can use >1) |
8) Debugging Probes (Commands)
# 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 -ltnp9) 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