Tag 17: Rollouts, Autoscaling, Jobs und Helm
Ziel: Du erkennst hängende Rollouts, einen blinden HPA, ein festgefahrenes Helm-Release, einen aufgebenden Job und Konfiguration, die nicht ankommt – und weißt jeweils, welcher Befehl die Wahrheit sagt. · Dauer: ca. 75 min · Voraussetzung: Tag 16
Briefing
- Ein Deployment-Rollout endet nicht mit einem Fehler, sondern mit
einer Condition:
Progressing=False, ReasonProgressDeadlineExceeded. - Der HPA rechnet in Prozent der Requests; ohne Request kein Ziel.
- Helm speichert jeden Release-Stand als Secret. Stirbt Helm mitten im
Upgrade, bleibt der Stand
pending-upgrade– und blockiert jedes weitere Upgrade. - ConfigMap-Änderungen erreichen nur Volumes ohne
subPath, nie Umgebungsvariablen.
| Fehlerbild | Symptom | Wo die Antwort steht |
|---|---|---|
| Rollout hängt | exceeded its progress deadline |
Conditions, ReplicaSets |
| HPA blind | cpu: <unknown>/50% |
Events am HPA |
| Helm blockiert | another operation … in progress |
helm history |
| Job gibt auf | BackoffLimitExceeded |
Job-Conditions, Logs |
| Konfiguration alt | Pod liest alten Wert | Env vs. subPath vs. Volume |
Drill 1: Der Rollout hängt
Einbauen: Drei web-Pods; die Frist für
Fortschritt ist im Labor auf 30 Sekunden verkürzt (Standard 600). Dann
ein Image-Tag, das es nicht gibt:
# auf cp1
mkdir -p ~/debug/tag17 && cd ~/debug/tag17
kubectl create namespace tag17
cat > web.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: web, namespace: tag17}
spec:
replicas: 3
progressDeadlineSeconds: 30
selector: {matchLabels: {app: web}}
template:
metadata: {labels: {app: web}}
spec:
containers:
- name: web
image: traefik/whoami:v1.11
EOF
kubectl apply -f web.yaml
kubectl -n tag17 rollout status deploy/web
kubectl -n tag17 set image deploy/web web=traefik/whoami:v1.99Erwartet (gekürzt):
namespace/tag17 created
deployment.apps/web created
deployment "web" successfully rolled out
deployment.apps/web image updated
Symptom:
# auf cp1
kubectl -n tag17 rollout status deploy/web --timeout=90s; echo "rc=$?"
kubectl -n tag17 get deploy webErwartet (gekürzt):
error: deployment "web" exceeded its progress deadline
rc=1
NAME READY UP-TO-DATE AVAILABLE AGE
web 3/3 1 3 34s
3/3 bereit, aber nur einer UP-TO-DATE – der
Dienst läuft, das Update nicht.
Untersuchen:
# auf cp1
kubectl -n tag17 get rs
kubectl -n tag17 get pods
J='{range .status.conditions[*]}{.type}={.status} {.reason}{"\n"}{end}'
kubectl -n tag17 get deploy web -o jsonpath="$J"Erwartet:
NAME DESIRED CURRENT READY AGE
web-5ccbc58945 3 3 3 37s
web-6577c6f697 1 1 0 35s
NAME READY STATUS RESTARTS AGE
web-5ccbc58945-fmq5t 1/1 Running 0 37s
web-5ccbc58945-gbwk4 1/1 Running 0 37s
web-5ccbc58945-j9nq2 1/1 Running 0 37s
web-6577c6f697-fj6g4 0/1 ErrImagePull 0 35s
Available=True MinimumReplicasAvailable
Progressing=False ProgressDeadlineExceeded
Ursache: Das neue ReplicaSet bekommt keinen bereiten
Pod (Tag 4). Die Standard-Strategie (maxSurge 25 %,
maxUnavailable 25 % – bei drei Replikas abgerundet null)
startet einen neuen Pod und baut keinen alten ab, solange der neue nicht
bereit ist. Nach progressDeadlineSeconds setzt der
Controller ProgressDeadlineExceeded – er bricht
nicht ab, er meldet nur.
Fix:
# auf cp1
kubectl -n tag17 rollout history deploy/web
kubectl -n tag17 rollout undo deploy/web 2>&1 | tail -1
kubectl -n tag17 rollout status deploy/webErwartet (gekürzt):
deployment.apps/web
REVISION CHANGE-CAUSE
1 <none>
2 <none>
deployment.apps/web rolled back
deployment "web" successfully rolled out
rollout undo warnt in 1.37, dass die Annotation von
kubectl apply nicht mitzieht. Kam der Fehler über
kubectl apply, korrigierst du deshalb die Datei – sonst
bringt das nächste apply ihn zurück.
Nachweis:
# auf cp1
kubectl -n tag17 get deploy web
kubectl -n tag17 get deploy web \
-o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'Erwartet:
NAME READY UP-TO-DATE AVAILABLE AGE
web 3/3 3 3 45s
traefik/whoami:v1.11
Fortschritt speichern? Kostenlos registrieren
Drill 2: Der HPA sieht nichts
Einbauen:
# auf cp1
kubectl -n tag17 autoscale deploy web --cpu=50% --min=2 --max=5Erwartet:
horizontalpodautoscaler.autoscaling/web autoscaled
Symptom (nach etwa 45 Sekunden):
# auf cp1
sleep 45
kubectl -n tag17 get hpaErwartet:
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
web Deployment/web cpu: <unknown>/50% 2 5 3 49s
Untersuchen:
# auf cp1
kubectl -n tag17 events --for hpa/web --types=Warning | tail -2 | cut -c1-200 \
| fold -w 86
kubectl top pods -n tag17 | head -2Erwartet (gekürzt):
6s Warning FailedGetResourceMetric HorizontalPodAutoscaler/w
eb failed to get cpu utilization: missing request for cpu in container web of Pod we
b-5ccbc58945-gbwk4
...
NAME CPU(cores) MEMORY(bytes)
web-5ccbc58945-fmq5t 0m 1Mi
Ursache: 50% heißt 50 Prozent des
CPU-Requests. Der Container hat keinen Request, also
gibt es nichts, wovon 50 Prozent zu rechnen wären.
kubectl top liefert dagegen Werte – der metrics-server (Tag
16) ist nicht das Problem.
Fix:
# auf cp1
kubectl -n tag17 set resources deploy/web --requests=cpu=10m
kubectl -n tag17 rollout status deploy/webNachweis (nach etwa einer Minute):
# auf cp1
sleep 60
kubectl -n tag17 get hpaErwartet:
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
web Deployment/web cpu: 0%/50% 2 5 3 2m5s
REPLICAS bleibt noch bei 3, obwohl MINPODS
2 erlaubt: Der HPA wartet fünf Minuten (Stabilisierungsfenster), bevor
er herunterskaliert.
Fortschritt speichern? Kostenlos registrieren
Drill 3: Helm hängt in pending-upgrade
Einbauen: Ein Beispiel-Chart, installiert und dann mitten im Upgrade hart beendet – so wie ein abgebrochener CI-Job:
Achtung:
kill -9beendet Helm, ohne aufzuräumen. Nur im Labor.
# auf cp1
helm create demo
helm install demo ./demo -n tag17 --wait --timeout 2m | grep -E 'STATUS|REVISION'
helm upgrade demo ./demo -n tag17 --set image.tag=gibtsnicht --wait --timeout 5m &
sleep 5
kill -9 %1Erwartet (gekürzt):
Creating demo
STATUS: deployed
REVISION: 1
Nach kill -9 meldet die Shell den Abbruch des
Hintergrundjobs (Killed helm upgrade demo …).
Symptom:
# auf cp1
helm upgrade demo ./demo -n tag17 2>&1 | tail -1Erwartet:
Error: UPGRADE FAILED: another operation (install/upgrade/rollback) is in progress
Untersuchen:
# auf cp1
helm -n tag17 history demo -o json \
| jq -r '.[] | "\(.revision) \(.status) \(.description)"'
helm list -n tag17 -o json | jq -r '.[] | "\(.name) \(.revision) \(.status)"'
kubectl -n tag17 get secret -l owner=helmErwartet:
1 deployed Install complete
2 pending-upgrade Preparing upgrade
demo 2 pending-upgrade
NAME TYPE DATA AGE
sh.helm.release.v1.demo.v1 helm.sh/release.v1 1 14s
sh.helm.release.v1.demo.v2 helm.sh/release.v1 1 10s
Ursache: Helm schreibt zu Beginn des Upgrades
Revision 2 als pending-upgrade und erst am Ende
deployed oder failed. kill -9
lässt den Zwischenstand stehen, und jedes weitere Upgrade glaubt, ein
anderes laufe noch. Helm 4 kennt helm list -a nicht mehr;
list zeigt alle Stände.
Fix: Auf die letzte gute Revision zurück:
# auf cp1
helm -n tag17 rollback demo 1 2>&1 | tail -1
helm -n tag17 history demo -o json \
| jq -r '.[] | "\(.revision) \(.status) \(.description)"'Erwartet:
Rollback was a success! Happy Helming!
1 superseded Install complete
2 pending-upgrade Preparing upgrade
3 deployed Rollback to 1
Revision 2 bleibt in der Historie als pending-upgrade
stehen – maßgeblich ist die neueste.
Nachweis:
# auf cp1
helm upgrade demo ./demo -n tag17 --wait | grep -E 'STATUS|REVISION'Erwartet:
STATUS: deployed
REVISION: 4
Fortschritt speichern? Kostenlos registrieren
Drill 4: Der Job gibt auf
Einbauen: Ein Import, der jedes Mal mit Exit-Code 3 scheitert:
# auf cp1
cat > job.yaml <<'EOF'
apiVersion: batch/v1
kind: Job
metadata: {name: import, namespace: tag17}
spec:
backoffLimit: 3
template:
spec:
restartPolicy: Never
containers:
- name: import
image: busybox:1.37
command: [sh, -c, "echo Datei fehlt; exit 3"]
EOF
kubectl apply -f job.yamlSymptom:
# auf cp1
T0=$(date +%s)
kubectl -n tag17 wait --for=condition=Failed job/import --timeout=180s
echo "nach $(( $(date +%s) - T0 )) s"
kubectl -n tag17 get job import
kubectl -n tag17 get pods -l job-name=importErwartet:
job.batch/import condition met
nach 75 s
NAME STATUS COMPLETIONS DURATION AGE
import Failed 0/1 78s 78s
NAME READY STATUS RESTARTS AGE
import-2jv7f 0/1 Error 0 5s
import-4x2vx 0/1 Error 0 67s
import-j6pql 0/1 Error 0 79s
import-vtrqf 0/1 Error 0 46s
Untersuchen:
# auf cp1
J='{range .status.conditions[*]}{.type}={.status} {.reason}: {.message}{"\n"}{end}'
kubectl -n tag17 get job import -o jsonpath="$J"
kubectl -n tag17 logs job/importErwartet:
FailureTarget=True BackoffLimitExceeded: Job has reached the specified backoff limit
Failed=True BackoffLimitExceeded: Job has reached the specified backoff limit
Found 4 pods, using pod/import-j6pql
Datei fehlt
Ursache: Ein Versuch plus drei Wiederholungen
(backoffLimit: 3), mit wachsender Pause (10 s, 20 s, 40 s)
– 75 Sekunden für einen Fehler, der beim ersten Mal klar war. Exit-Code
3 heißt hier „Eingabe fehlt“; Wiederholen hilft nie.
Fix: Eine podFailurePolicy lässt den
Job bei genau diesem Exit-Code sofort scheitern:
# auf cp1
kubectl -n tag17 delete job import
cat > job.yaml <<'EOF'
apiVersion: batch/v1
kind: Job
metadata: {name: import, namespace: tag17}
spec:
backoffLimit: 3
podFailurePolicy:
rules:
- action: FailJob
onExitCodes: {containerName: import, operator: In, values: [3]}
template:
spec:
restartPolicy: Never
containers:
- name: import
image: busybox:1.37
command: [sh, -c, "echo Datei fehlt; exit 3"]
EOF
kubectl apply -f job.yamlNachweis:
# auf cp1
T0=$(date +%s)
kubectl -n tag17 wait --for=condition=Failed job/import --timeout=180s
echo "nach $(( $(date +%s) - T0 )) s"
kubectl -n tag17 get job import -o jsonpath='{.status.conditions[-1].message}{"\n"}' \
| fold -w 86Erwartet:
job.batch/import condition met
nach 2 s
Container import for pod tag17/import-6xtnh failed with exit code 3 matching FailJob r
ule at index 0
Ein Pod statt vier, und die Meldung nennt den Grund. Mit
action: Ignore und
onPodConditions: [{type: DisruptionTarget}] zählen Abbrüche
durch Eviction oder Preemption gar nicht gegen
backoffLimit.
Fortschritt speichern? Kostenlos registrieren
Drill 5: Die Konfiguration kommt nicht an
Einbauen: Ein Pod liest denselben
ConfigMap-Schlüssel auf drei Wegen – als Umgebungsvariable, als einzelne
Datei per subPath und als Volume:
# auf cp1
cat > konfig.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata: {name: app-konfig, namespace: tag17}
data:
farbe: blau
---
apiVersion: apps/v1
kind: Deployment
metadata: {name: leser, namespace: tag17}
spec:
replicas: 1
selector: {matchLabels: {app: leser}}
template:
metadata: {labels: {app: leser}}
spec:
containers:
- name: leser
image: busybox:1.37
command: [sleep, infinity]
env:
- name: FARBE
valueFrom: {configMapKeyRef: {name: app-konfig, key: farbe}}
volumeMounts:
- {name: konfig, mountPath: /etc/app/farbe, subPath: farbe}
- {name: konfig, mountPath: /konfig}
volumes:
- name: konfig
configMap: {name: app-konfig}
EOF
kubectl apply -f konfig.yaml
kubectl -n tag17 rollout status deploy/leser
kubectl -n tag17 patch configmap app-konfig -p '{"data":{"farbe":"rot"}}'Symptom (nach etwa einer Minute):
# auf cp1
sleep 60
kubectl -n tag17 exec deploy/leser -- \
sh -c 'echo env=$FARBE subPath=$(cat /etc/app/farbe) volume=$(cat /konfig/farbe)'Erwartet:
env=blau subPath=blau volume=rot
Ursache: Umgebungsvariablen werden nur beim Start
gesetzt. Ein subPath-Mount ist eine einzelne, beim Start
festgelegte Datei – das Kubelet tauscht sie nie aus. Nur das Volume ohne
subPath folgt der ConfigMap (über einen Symlink, nach bis
zu etwa einer Minute).
Fix: Neu ausrollen – oder die Anwendung liest aus dem Volume-Verzeichnis:
# auf cp1
kubectl -n tag17 rollout restart deploy/leser
kubectl -n tag17 rollout status deploy/leserNachweis:
# auf cp1
kubectl -n tag17 exec deploy/leser -- \
sh -c 'echo env=$FARBE subPath=$(cat /etc/app/farbe) volume=$(cat /konfig/farbe)'Erwartet:
env=rot subPath=rot volume=rot
Fortschritt speichern? Kostenlos registrieren
Übung: Speed-Drills
- Zeig die Conditions des Deployments
webmit Reason. Zeitziel: 30 s - Zeig alle Helm-Releases im Cluster, die nicht
deployedsind. Zeitziel: 20 s - Zeig alle fehlgeschlagenen Jobs im Cluster. Zeitziel: 30 s
Lösung
# auf cp1
J='{range .status.conditions[*]}{.type}={.status} {.reason}{"\n"}{end}'
kubectl -n tag17 get deploy web -o jsonpath="$J"
helm list -A --pending --failed -q; echo "rc=$?"
kubectl get jobs -A | grep -E 'NAME|Failed' | tr -s ' 'Erwartet:
Available=True MinimumReplicasAvailable
Progressing=True NewReplicaSetAvailable
rc=0
NAMESPACE NAME STATUS COMPLETIONS DURATION AGE
tag17 import Failed 0/1 89s 89s
-q gibt nur Namen aus – hier keinen, das Helm-Release
ist nach Drill 3 sauber.
Fortschritt speichern? Kostenlos registrieren
Kontrollpunkt
# auf cp1
kubectl -n tag17 get deploy
helm -n tag17 status demo -o json | jq -r .info.statusErwartet:
NAME READY UP-TO-DATE AVAILABLE AGE
demo 1/1 1 1 3m25s
leser 1/1 1 1 84s
web 2/2 2 2 6m22s
deployed
web steht jetzt auf 2 – das Stabilisierungsfenster des
HPA ist abgelaufen.
Challenge
Das Deployment api bekommt eine neue Readiness-Probe.
Seit zwei Minuten meldet der Rollout nichts Neues, Fehler gibt es keine,
der Dienst läuft. Finde heraus, woran der Rollout hängt, und bring ihn
in einen sauberen Zustand.
# auf cp1
cat > api.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: api, namespace: tag17}
spec:
replicas: 3
strategy:
rollingUpdate: {maxSurge: 1, maxUnavailable: 0}
selector: {matchLabels: {app: api}}
template:
metadata: {labels: {app: api}}
spec:
containers:
- name: api
image: traefik/whoami:v1.11
readinessProbe:
httpGet: {path: /, port: 80}
EOF
kubectl apply -f api.yaml
kubectl -n tag17 rollout status deploy/api
P=/spec/template/spec/containers/0/readinessProbe/httpGet/port
kubectl -n tag17 patch deploy api --type=json \
-p '[{"op": "replace", "path": "'$P'", "value": 8080}]'Hinweis: Mit der Standardfrist von 600 Sekunden
kommt ProgressDeadlineExceeded erst in zehn Minuten – schau
dir die ReplicaSets an.
Lösung
# auf cp1
sleep 40
kubectl -n tag17 rollout status deploy/api --timeout=5s
kubectl -n tag17 get rs -l app=api
kubectl -n tag17 get pods -l app=api
kubectl -n tag17 events --types=Warning | grep 'Pod/api' | grep -m1 Unhealthy \
| cut -c1-200 | fold -w 86Erwartet:
Waiting for deployment "api" rollout to finish: 1 out of 3 new replicas have been upda
ted...
error: timed out waiting for the condition
NAME DESIRED CURRENT READY AGE
api-6745d6c768 1 1 0 48s
api-77d7d744d8 3 3 3 51s
NAME READY STATUS RESTARTS AGE
api-6745d6c768-dtp5c 0/1 Running 0 49s
api-77d7d744d8-c2f8c 1/1 Running 0 52s
api-77d7d744d8-hxdzb 1/1 Running 0 52s
api-77d7d744d8-rqq4m 1/1 Running 0 52s
7s (x7 over 47s) Warning Unhealthy Pod/api-6745d6c768-dt
p5c Readiness probe failed: Get "http://10.42.0.168:8080/": dial tcp 10.42.0.168:
8080: connect: connection re
Der neue Pod läuft, wird aber nie bereit – die Probe fragt Port 8080,
whoami hört auf 80. Mit maxUnavailable: 0
bleiben alle drei alten Pods stehen: kein Ausfall, aber auch kein
Fortschritt. Zurück auf die letzte gute Version:
# auf cp1
kubectl -n tag17 rollout undo deploy/api 2>&1 | tail -1
kubectl -n tag17 rollout status deploy/api
kubectl -n tag17 get rs -l app=apiErwartet (gekürzt):
deployment.apps/api rolled back
deployment "api" successfully rolled out
NAME DESIRED CURRENT READY AGE
api-6745d6c768 0 0 0 53s
api-77d7d744d8 3 3 3 56s
Fortschritt speichern? Kostenlos registrieren
Aufräumen
# auf cp1
helm uninstall demo -n tag17
kubectl delete namespace tag17
helm list -A | grep -c demoErwartet:
release "demo" uninstalled
namespace "tag17" deleted
0
Interview-Notiz
- Rollout hängt – woran sehe ich es?
rollout statusbricht mitexceeded its progress deadlineab;get rszeigt das neue ReplicaSet ohne bereite Pods. Der Controller rollt nicht selbst zurück. - HPA zeigt
<unknown>? Events am HPA: fehlender Request oder fehlende Metrics-API (kubectl get apiservice, Tag 16). - Helm
another operation is in progress?helm historyzeigtpending-*;helm rollbackauf die letzte gute Revision, nie die Release-Secrets von Hand löschen.
Enterprise-Notiz
progressDeadlineSecondskurz genug wählen, dass CI-Pipelines mitrollout statusscheitern, statt eine Stunde zu warten; automatischer Rollback gehört in die Pipeline oder zu Argo Rollouts/Flagger.- Helm in CI immer mit
--rollback-on-failure(in Helm 3:--atomic) und Timeout; parallele Pipelines auf dasselbe Release verhindern. - Requests für alle Container erzwingen (LimitRange, Kyverno), sonst ist jeder HPA blind.
- Konfiguration über Volumes ohne
subPathoder mit Hash im Pod-Template (Checksum-Annotation im Helm-Chart), damit Änderungen einen Rollout auslösen.