forked from mtusi2026/mtusi2026lab4
22 lines
1.7 KiB
Bash
Executable File
22 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Restart only this lab's API and persistent stores, retaining every PVC.
|
|
set -eu
|
|
: "${KUBE_CONTEXT:=dev}" "${NAMESPACE:=highload-applications}"
|
|
# HPA must be disabled explicitly for this destructive test window.
|
|
if kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get hpa api >/dev/null 2>&1; then
|
|
echo 'Disable autoscaling in the lab release before the restart test, then restore it.' >&2
|
|
exit 1
|
|
fi
|
|
replicas=$(kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get deployment api -o jsonpath='{.spec.replicas}')
|
|
mkdir -p evidence
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods -l 'app in (api,postgres,valkey,s3)' -o custom-columns=NAME:.metadata.name,UID:.metadata.uid > evidence/restart-before.txt
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" scale deployment/api --replicas=0
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" wait --for=delete pod -l app=api --timeout=60s
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" rollout restart statefulset/postgres statefulset/valkey statefulset/s3
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" rollout status statefulset/postgres --timeout=120s
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" rollout status statefulset/valkey --timeout=120s
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" rollout status statefulset/s3 --timeout=120s
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" scale deployment/api --replicas="$replicas"
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" rollout status deployment/api --timeout=120s
|
|
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods -l 'app in (api,postgres,valkey,s3)' -o custom-columns=NAME:.metadata.name,UID:.metadata.uid > evidence/restart-after.txt
|