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
rollout statuswaits for the new ReplicaSet to be fully available and exits non-zero on timeout or progress deadline.- Set
progressDeadlineSecondsin 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.
More on Scenarios: deployments, user management and fleet operations
Write the core of a deploy script with release directories, an atomic symlink switch and rollback.IntermediateDeploy to 10 servers behind an AWS ALB one at a time, removing each from the target group during its deploy. Outline the script.AdvancedAfter a deploy, the health check fails intermittently. Your script must roll back automatically, but only if the failure persists. How?IntermediateImplement a blue/green switch on a single nginx host with a script.AdvancedOnboard 30 engineers: create accounts and install their SSH keys from their GitHub usernames, idempotently.IntermediateAn engineer leaves the company. Write the offboarding steps for Linux servers.Intermediate