How to Use kubectl rollout to Manage Kubernetes Deployments
Use
kubectl rollout commands to manage the deployment lifecycle in Kubernetes. You can check rollout status, undo changes, and pause or resume deployments with commands like kubectl rollout status, kubectl rollout undo, and kubectl rollout pause/resume.Syntax
The kubectl rollout command manages the rollout of Kubernetes resources like deployments. It has several subcommands:
status: Shows the current rollout status.undo: Reverts to a previous deployment revision.pause: Pauses the rollout to stop updates temporarily.resume: Resumes a paused rollout.
Each subcommand requires the resource type and name.
bash
kubectl rollout status deployment/<deployment-name> kubectl rollout undo deployment/<deployment-name> kubectl rollout pause deployment/<deployment-name> kubectl rollout resume deployment/<deployment-name>
Example
This example shows how to check the rollout status, pause a deployment, and then undo the last rollout for a deployment named my-app.
bash
kubectl rollout status deployment/my-app kubectl rollout pause deployment/my-app kubectl rollout undo deployment/my-app
Output
deployment "my-app" successfully rolled out
deployment "my-app" paused
deployment "my-app" rolled back
Common Pitfalls
Common mistakes include:
- Using
kubectl rollout undowithout specifying the deployment, which causes an error. - Trying to pause or resume a resource that is not a deployment or does not support rollout.
- Not waiting for the rollout status to complete before making further changes.
Always specify the correct resource type and name, and check status before undoing or pausing.
bash
kubectl rollout undo my-app # Wrong: missing resource type kubectl rollout undo deployment/my-app # Correct: includes resource type
Output
error: resource(s) were provided, but no name, label selector, or --all flag specified
deployment "my-app" rolled back
Quick Reference
| Command | Description |
|---|---|
| kubectl rollout status deployment/ | Show rollout status of a deployment |
| kubectl rollout undo deployment/ | Revert to previous deployment revision |
| kubectl rollout pause deployment/ | Pause the deployment rollout |
| kubectl rollout resume deployment/ | Resume a paused deployment rollout |
Key Takeaways
Use kubectl rollout commands to control deployment updates safely.
Always specify the resource type and name with rollout commands.
Check rollout status before undoing or pausing deployments.
Pause rollouts to safely apply changes or troubleshoot.
Undo rollouts to quickly revert to a stable deployment version.