Bird
Raised Fist0
Kubernetesdevops~30 mins

Rollback to previous version in Kubernetes - Mini Project: Build & Apply

Choose your learning style10 modes available
Rollback to Previous Version in Kubernetes
📖 Scenario: You are managing a web application deployed on Kubernetes. After updating the application to a new version, you notice issues and want to rollback to the previous stable version.
🎯 Goal: Learn how to rollback a Kubernetes deployment to its previous version using kubectl commands.
📋 What You'll Learn
Create a Kubernetes deployment named webapp with version v1 of the container image
Update the deployment to version v2 of the container image
Rollback the deployment to the previous version
Display the current image version of the deployment after rollback
💡 Why This Matters
🌍 Real World
In real-world Kubernetes environments, deployments are frequently updated. Sometimes new versions cause issues. Knowing how to quickly rollback to a stable version helps keep applications running smoothly.
💼 Career
DevOps engineers and site reliability engineers often manage Kubernetes deployments. Mastering rollback commands is essential for maintaining application uptime and reliability.
Progress0 / 4 steps
1
Create initial deployment with version v1
Use kubectl create deployment webapp --image=nginx:1.19 to create a deployment named webapp with the image version 1.19 (representing version v1).
Kubernetes
Hint

This command creates a deployment named webapp using the nginx image version 1.19.

2
Update deployment to version v2
Use kubectl set image deployment/webapp webapp=nginx:1.20 to update the webapp deployment's container image to version 1.20 (representing version v2).
Kubernetes
Hint

This command updates the container image of the webapp deployment to nginx version 1.20.

3
Rollback deployment to previous version
Use kubectl rollout undo deployment/webapp to rollback the webapp deployment to its previous version.
Kubernetes
Hint

This command rolls back the deployment to the last stable version before the update.

4
Check current image version after rollback
Use kubectl get deployment webapp -o=jsonpath='{.spec.template.spec.containers[0].image}' to display the current container image version of the webapp deployment after rollback.
Kubernetes
Hint

This command prints the current image used by the deployment, which should be nginx:1.19 after rollback.

Practice

(1/5)
1. What does the command kubectl rollout undo deployment/myapp do in Kubernetes?
easy
A. It updates the deployment 'myapp' to the latest image version.
B. It rolls back the deployment 'myapp' to its previous version.
C. It deletes the deployment 'myapp' permanently.
D. It scales the deployment 'myapp' to zero replicas.

Solution

  1. Step 1: Understand the command purpose

    The command kubectl rollout undo is used to revert a deployment to a previous state.
  2. Step 2: Apply to the given deployment

    Using deployment/myapp specifies which deployment to rollback.
  3. Final Answer:

    It rolls back the deployment 'myapp' to its previous version. -> Option B
  4. Quick Check:

    Rollback command = revert deployment [OK]
Hint: Rollback uses 'kubectl rollout undo' with deployment name [OK]
Common Mistakes:
  • Confusing rollback with delete command
  • Thinking it updates to latest version instead of previous
  • Using scale command instead of rollback
2. Which of the following is the correct syntax to rollback a deployment named 'webapp' to its previous version?
easy
A. kubectl rollout undo deployment/webapp
B. kubectl rollback deployment/webapp
C. kubectl undo deployment webapp
D. kubectl rollback undo webapp

Solution

  1. Step 1: Recall correct rollback syntax

    The correct command to rollback is kubectl rollout undo deployment/<name>.
  2. Step 2: Match syntax with deployment name

    Replacing <name> with 'webapp' gives kubectl rollout undo deployment/webapp.
  3. Final Answer:

    kubectl rollout undo deployment/webapp -> Option A
  4. Quick Check:

    Correct rollback syntax = rollout undo [OK]
Hint: Remember 'rollout undo' is the rollback command [OK]
Common Mistakes:
  • Using 'rollback' instead of 'rollout undo'
  • Incorrect order of words in command
  • Missing 'deployment/' prefix
3. Given the following commands executed in order:
kubectl apply -f deployment-v1.yaml
kubectl apply -f deployment-v2.yaml
kubectl rollout undo deployment/myapp

What will be the current version of the deployment 'myapp' after the last command?
medium
A. Version 1 (deployment-v1.yaml)
B. Version 2 (deployment-v2.yaml)
C. No change, still version 2
D. Deployment deleted

Solution

  1. Step 1: Understand deployment updates

    First, version 1 is applied, then version 2 updates the deployment.
  2. Step 2: Rollback command effect

    The rollback command reverts the deployment to the previous version, which is version 1.
  3. Final Answer:

    Version 1 (deployment-v1.yaml) -> Option A
  4. Quick Check:

    Rollback reverts to last version before update [OK]
Hint: Rollback returns to version before last update [OK]
Common Mistakes:
  • Assuming rollback deletes deployment
  • Thinking rollback keeps current version
  • Confusing rollback with reapply
4. You tried to rollback a deployment using kubectl rollout undo deployment/myapp but got an error: error: no rollout found. What is the most likely cause?
medium
A. Rollback command requires a namespace flag.
B. You misspelled the deployment name in the command.
C. The deployment 'myapp' has no previous versions to rollback to.
D. The Kubernetes cluster is down.

Solution

  1. Step 1: Analyze the error message

    The error 'no rollout found' means no previous rollout history exists for rollback.
  2. Step 2: Identify cause

    This usually happens if the deployment was never updated or has only one version.
  3. Final Answer:

    The deployment 'myapp' has no previous versions to rollback to. -> Option C
  4. Quick Check:

    No rollout history = no rollback possible [OK]
Hint: Check rollout history before rollback [OK]
Common Mistakes:
  • Assuming cluster is down causes this error
  • Forgetting to check deployment name spelling
  • Thinking rollback always works without history
5. You have a deployment 'api-server' with three revisions in history. You want to rollback to revision 2 specifically. Which command should you use?
hard
A. kubectl rollout undo deployment/api-server revision=2
B. kubectl rollback deployment/api-server --revision=2
C. kubectl undo deployment/api-server revision 2
D. kubectl rollout undo deployment/api-server --to-revision=2

Solution

  1. Step 1: Recall rollback to specific revision syntax

    The correct syntax to rollback to a specific revision is kubectl rollout undo deployment/<name> --to-revision=<number>.
  2. Step 2: Apply to 'api-server' and revision 2

    Replacing placeholders gives kubectl rollout undo deployment/api-server --to-revision=2.
  3. Final Answer:

    kubectl rollout undo deployment/api-server --to-revision=2 -> Option D
  4. Quick Check:

    Use '--to-revision' flag to rollback specific version [OK]
Hint: Use '--to-revision' flag to rollback specific version [OK]
Common Mistakes:
  • Using incorrect flags like --revision or wrong command order
  • Omitting '--to-revision' flag
  • Using 'rollback' instead of 'rollout undo'
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard