Skip to content
CNPE · Chapter 13 of 22 Day 11: Operations – five incidents

Day 11: Operations – five incidents

Goal: Recognise, narrow down and fix five typical incidents – with a fixed sequence of commands instead of guessing – and turn them into a runbook for the platform · Duration: approx. 60 min · Prerequisite: Day 10

Briefing

  • “The pod isn’t running” almost always has one of five causes, in the exam as in operations. Each leaves its own trace:
Status Usual cause Trace is found in
OOMKilled, exit 137 Memory limit too small or a leak lastState.terminated
Error/CrashLoopBackOff, exit 1 Application exits: configuration, dependency Logs
Pending Scheduler finds no node Events FailedScheduling
Running, but 0/1 Readiness probe fails, Service without endpoints Events Unhealthy, EndpointSlices
ImagePullBackOff Image name, tag, registry, credentials Events Failed
  • The sequence: status (get pods) → events (describe, get events) → logs → the object itself (get -o yaml). If you start with the logs, you search in vain for Pending and ImagePull.
  • Kubernetes already watches all of this: kube-prometheus-stack (Day 10) ships alerts such as KubePodCrashLooping – but they only fire after 15 minutes.

Drill 1: The incidents

Team Gelb ships five services, each with a fault. Don’t read the manifests closely – find the faults through the cluster, as you would in operations.

# on cp1
mkdir -p ~/cnpe/tag11 && cd ~/cnpe/tag11
cat > stoerungen.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: speicherfresser
  namespace: team-gelb
spec:
  selector:
    matchLabels: {app: speicherfresser}
  template:
    metadata:
      labels: {app: speicherfresser}
    spec:
      containers:
      - name: app
        image: busybox:1.37
        command: ["sh", "-c", "echo Lade Katalog in den Speicher; head -c 400m /dev/zero | tail; sleep 3600"]
        resources:
          limits: {memory: 256Mi}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: absturz
  namespace: team-gelb
spec:
  selector:
    matchLabels: {app: absturz}
  template:
    metadata:
      labels: {app: absturz}
    spec:
      containers:
      - name: app
        image: busybox:1.37
        command: ["sh", "-c", "test -f /config/app.conf || { echo FEHLER: /config/app.conf fehlt >&2; exit 1; }; sleep 3600"]
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wartet
  namespace: team-gelb
spec:
  selector:
    matchLabels: {app: wartet}
  template:
    metadata:
      labels: {app: wartet}
    spec:
      nodeSelector:
        disk: ssd
      containers:
      - name: app
        image: nginx:1.29-alpine
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: unbereit
  namespace: team-gelb
spec:
  replicas: 2
  selector:
    matchLabels: {app: unbereit}
  template:
    metadata:
      labels: {app: unbereit}
    spec:
      containers:
      - name: app
        image: nginx:1.29-alpine
        readinessProbe:
          httpGet: {path: /, port: 8080}
          periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: unbereit
  namespace: team-gelb
spec:
  selector: {app: unbereit}
  ports: [{port: 80}]
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tippfehler
  namespace: team-gelb
spec:
  selector:
    matchLabels: {app: tippfehler}
  template:
    metadata:
      labels: {app: tippfehler}
    spec:
      containers:
      - name: app
        image: ngnix:1.29-alpine
EOF
k apply -f stoerungen.yaml
sleep 90
k -n team-gelb get pods

Expected:

NAME                              READY   STATUS             RESTARTS      AGE
absturz-8ff4457c6-4z9rj           0/1     Error              3 (74s ago)   91s
speicherfresser-dc465fdf6-mzmh5   0/1     OOMKilled          2 (46s ago)   91s
tippfehler-b57bf955d-fvvhs        0/1     ImagePullBackOff   0             91s
unbereit-684695979b-p8jj9         0/1     Running            0             91s
unbereit-684695979b-rzzp4         0/1     Running            0             91s
wartet-595bbdbbdd-mnn58           0/1     Pending            0             91s

The status changes: Error and CrashLoopBackOff are the same incident – between two restarts the kubelet waits longer and longer (10 s, 20 s, 40 s … up to 5 min).

Save your progress? Sign up for free

Drill 2: Speicherfresser – OOMKilled

# on cp1
# Reason and exit code of the container's last termination
k -n team-gelb get pod -l app=speicherfresser \
  -o jsonpath='{.items[0].status.containerStatuses[0].lastState.terminated.reason} exit={.items[0].status.containerStatuses[0].lastState.terminated.exitCode}{"\n"}'

Expected:

OOMKilled exit=137

137 = 128 + 9: the kernel killed the process with SIGKILL because the cgroup reached its memory limit. Logs rarely help here – the process gets no chance to write anything. The application needs around 400 MiB, the limit is 256 MiB:

# on cp1
# Raise the limit (Team Gelb's LimitRange allows up to 1 GiB)
k -n team-gelb set resources deploy/speicherfresser --limits=memory=512Mi

Expected:

deployment.apps/speicherfresser resource requirements updated

Save your progress? Sign up for free

Drill 3: Absturz – the application explains itself

# on cp1
P=$(k -n team-gelb get pod -l app=absturz -o name)
k -n team-gelb logs $P
k -n team-gelb logs $P --previous

Expected:

FEHLER: /config/app.conf fehlt
unable to retrieve container logs for containerd://33c5fa762c1c6ecf61c08f8cc92ca6931d2943eadb5177561639b44648d52d4c

k logs shows the most recently run container, even if it has already terminated. --previous shows the one before it – the kubelet keeps only one terminated container. You need --previous when the container is running again and the fault happened during the last run.

The missing file comes from a ConfigMap:

# on cp1
k -n team-gelb create configmap app-config --from-literal=app.conf='modus=produktion'
# Add volume and mount via JSON patch (kubectl has no dedicated command for this)
k -n team-gelb patch deploy absturz --type=json -p '[
  {"op":"add","path":"/spec/template/spec/volumes","value":[{"name":"config","configMap":{"name":"app-config"}}]},
  {"op":"add","path":"/spec/template/spec/containers/0/volumeMounts","value":[{"name":"config","mountPath":"/config"}]}]'
k -n team-gelb rollout status deploy/absturz --timeout=90s

Expected (abridged):

configmap/app-config created
deployment.apps/absturz patched
deployment "absturz" successfully rolled out

Save your progress? Sign up for free

Drill 4: Wartet – Pending

# on cp1
k -n team-gelb get events --field-selector reason=FailedScheduling -o custom-columns=MSG:.message --no-headers | tail -1

Expected:

0/3 nodes are available: 1 node(s) had untolerated taint(s), 2 node(s) didn't match Pod's node affinity/selector. preemption: 0/3 nodes are available: 3 Preemption is not helpful for scheduling.

The message lists the reason for each node: cp1 has a taint, the workers don’t match the nodeSelector (disk: ssd). Two solutions: remove the selector, or label a node to match. Here, worker2 really does have the faster disk:

# on cp1
k label node worker2 disk=ssd
sleep 15
k -n team-gelb get pod -l app=wartet -o wide

Expected (abridged):

node/worker2 labeled
NAME                      READY   STATUS    RESTARTS   AGE     IP   NODE
wartet-595bbdbbdd-mnn58   1/1     Running   0          4m45s   …    worker2

The pod did not have to be recreated – the scheduler retries pending pods as soon as something changes in the cluster.

Save your progress? Sign up for free

Drill 5: Unbereit – running, but getting no traffic

# on cp1
# Endpoints of the Service: which pods get traffic?
k -n team-gelb get endpointslices -l kubernetes.io/service-name=unbereit \
  -o custom-columns=NAME:.metadata.name,READY:.endpoints[*].conditions.ready
k -n team-gelb get events --field-selector reason=Unhealthy -o custom-columns=MSG:.message --no-headers | tail -1

Expected:

NAME             READY
unbereit-svgn8   false,false
Readiness probe failed: Get "http://10.244.1.232:8080/": dial tcp 10.244.1.232:8080: connect: connection refused

nginx listens on 80, the probe asks 8080. The Service only sends requests to ready pods – here to none.

# on cp1
k -n team-gelb patch deploy unbereit --type=json \
  -p '[{"op":"replace","path":"/spec/template/spec/containers/0/readinessProbe/httpGet/port","value":80}]'
sleep 30
k -n team-gelb get endpointslices -l kubernetes.io/service-name=unbereit \
  -o custom-columns=NAME:.metadata.name,READY:.endpoints[*].conditions.ready

Expected:

deployment.apps/unbereit patched
NAME             READY
unbereit-svgn8   true,true

Save your progress? Sign up for free

Drill 6: Tippfehler – ImagePullBackOff

# on cp1
k -n team-gelb get events --field-selector reason=Failed -o custom-columns=MSG:.message --no-headers | grep ngnix | tail -1

Expected:

Failed to pull image "ngnix:1.29-alpine": failed to pull and unpack image "docker.io/library/ngnix:1.29-alpine": failed to resolve image: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

On Docker Hub, repository does not exist or may require authorization almost always means: wrong name. A private repo without credentials would look exactly the same – check the name first.

# on cp1
k -n team-gelb set image deploy/tippfehler app=nginx:1.29-alpine
sleep 30
k -n team-gelb get pods

Expected:

deployment.apps/tippfehler image updated
NAME                              READY   STATUS    RESTARTS   AGE
absturz-d74b4b47f-cm6lw           1/1     Running   0          7s
speicherfresser-6b77cb79b-kzfwp   1/1     Running   0          75s
tippfehler-54659444d4-r6wr7       1/1     Running   0          71s
unbereit-7dfb7b559b-784m9         1/1     Running   0          74s
unbereit-7dfb7b559b-vm98x         1/1     Running   0          69s
wartet-595bbdbbdd-mnn58           1/1     Running   0          4m58s

Save your progress? Sign up for free

Drill 7: What monitoring would have noticed

# on cp1
curl -s http://172.16.0.126:30090/api/v1/rules \
  | jq -r '.data.groups[].rules[] | select(.name=="KubePodCrashLooping" or .name=="KubePodNotReady" or .name=="KubeContainerWaiting") | "\(.name) for=\(.duration)s"'

Expected:

KubePodCrashLooping for=900s
KubePodNotReady for=900s
KubeContainerWaiting for=3600s

Four of the five incidents would have triggered an alert after 15 minutes to one hour. unbereit only via KubePodNotReady – an alert on “Service without ready endpoints” would be faster and closer to the symptom.

Save your progress? Sign up for free

Exercise: Runbook

Time limit: 10 minutes. Write a runbook runbooks/pod-startet-nicht.md for the platform repo with the commands from this day – one section per status: how to recognise it, which command, typical causes, remedy. Commit it.

Solution

# on cp1
cd ~/cnpe/plattform && git pull -q
mkdir -p runbooks
cat > runbooks/pod-startet-nicht.md <<'EOF'
# Pod startet nicht

Reihenfolge: `k get pods` → `k describe pod` / `k get events` → `k logs` → `k get pod -o yaml`

| Status | Befehl | Ursachen | Abhilfe |
|---|---|---|---|
| OOMKilled (137) | `k get pod -o jsonpath='{..lastState.terminated}'` | Limit zu klein, Leck | Limit anheben, Profiling |
| Error/CrashLoopBackOff | `k logs <pod>`, `--previous` wenn wieder läuft | Konfiguration, Abhängigkeit | Config/Secret, Abhängigkeit prüfen |
| Pending | `k get events --field-selector reason=FailedScheduling` | Ressourcen, Taints, Selektoren, PVC, Quota | Requests, Tolerations, Labels |
| Running 0/1 | `k get endpointslices -l kubernetes.io/service-name=<svc>` | Probe falsch, Abhängigkeit fehlt | Probe-Port/Pfad, Abhängigkeit |
| ImagePullBackOff | `k get events --field-selector reason=Failed` | Name/Tag, Registry, Zugangsdaten | Name prüfen, imagePullSecrets |
EOF
git add runbooks && git commit -qm 'Runbook: Pod startet nicht' && git push -q
git log --oneline -1

Expected (your hash will differ):

5785041 Runbook: Pod startet nicht

In the alert (Day 10), a runbook_url annotation points to this file in Gitea – whoever gets woken up at night lands directly on the right section.

Save your progress? Sign up for free

Challenge

Time limit: 10 minutes. A pod is Running and ready, but the application does not respond as expected. The image contains no shell, k exec fails. How do you look at the running container from the inside?

Solution

With a debug container that attaches to the pod and shares the target’s process namespace:

# on cp1
P=$(k -n team-gelb get pod -l app=tippfehler -o name)
#   --image      tool image with a shell
#   --target     container whose processes should become visible
#   -- ps aux    command in the debug container
k -n team-gelb debug $P -it --image=busybox:1.37 --target=app -- ps aux

Expected (abridged):

Targeting container "app". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
PID   USER     TIME  COMMAND
    1 root      0:00 nginx: master process nginx -g daemon off;
   29 101       0:00 nginx: worker process
   30 101       0:00 nginx: worker process
   31 root      0:00 ps aux

The debug container remains part of the pod until the pod ends (ephemeral container) – not a problem in the exam, but in production a reason to grant such permissions (pods/ephemeralcontainers) deliberately.

Save your progress? Sign up for free

Checkpoint

# on cp1
# all six pods of Team Gelb are running and ready (6)
k -n team-gelb get pods --no-headers | grep -c '1/1.*Running'
# worker2 carries the label
k get nodes -l disk=ssd -o name
# the runbook is in the repo
git -C ~/cnpe/plattform ls-files runbooks

Expected:

6
node/worker2
runbooks/pod-startet-nicht.md

Interview Note

  • How do you proceed when a pod doesn’t start? Status, events, logs, object – in this order. Status and events tell you where it is stuck; logs only help if the container ran at all.
  • What does exit code 137 mean? SIGKILL, with OOMKilled caused by the memory limit. 143 would be SIGTERM.
  • Running, but no traffic? Readiness. The Service only includes ready pods in its endpoints.

Enterprise Note

  • Runbooks for every alert (runbook_url), versioned next to the rules.
  • Events disappear after one hour – export them into a logging system (event exporter).
  • Collect logs centrally (Loki, OpenSearch); k logs only works as long as the pod exists.
  • Measure application memory and derive limits from it instead of guessing – Day 12.

Contents

More