Interview Prep/Shell Scripting/Scenarios: deployments, user management and fleet operations

A deploy script runs `kubectl apply` and must fail the pipeline, and roll back, if the rollout does not complete. Write it.

BeginnerScenarioScenarios: deployments, user management and fleet operations
Answer

Situation read → kubectl apply returns success as soon as the API accepts the object, not when pods are healthy.

What I'd do →

kubectl apply -f k8s/
if ! kubectl rollout status deployment/api -n prod --timeout=180s; then
  echo "rollout failed, undoing" >&2
  kubectl rollout undo deployment/api -n prod
  kubectl rollout status deployment/api -n prod --timeout=180s || true
  exit 1
fi
  1. rollout status waits for the new ReplicaSet to be fully available and exits non-zero on timeout or progress deadline.
  2. Set progressDeadlineSeconds in the Deployment so Kubernetes itself marks a stuck rollout as failed.

Why → Without waiting, CI goes green while pods crash-loop.

Interview tip → Mention that with GitOps, rollback means reverting the Git commit, not rollout undo.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: deployments, user management and fleet operations