The kubectl rollout
command is used to manage resource rollouts in Kubernetes clusters. Resource rollouts typically involve updating, reverting, or inspecting the status of resources like deployments, daemonsets, and statefulsets within your Kubernetes environment.
Here are several examples demonstrating how to use kubectl rollout
with different resource types:
1. Updating a Deployment:
To update a deployment named `myapp`, you can use the following command:
kubectl rollout restart deployment/myapp
This command restarts the pods of the deployment `myapp`, triggering a new rollout.
Verification: You can verify the rollout by checking the deployment’s revision history:
kubectl rollout history deployment/myapp
2. Inspecting Rollout Status:
Check the status of a rollout to monitor its progress:
kubectl rollout status deployment/myapp
This command shows whether the deployment is progressing as expected or if there are any issues.
3. Rolling Back a Deployment:
Roll back a deployment to a previous revision:
kubectl rollout undo deployment/myapp
This reverts the deployment `myapp` to the previous stable state.
Verification: Confirm the rollback by inspecting the deployment’s revision history.
4. Managing StatefulSets:
Perform a rolling update on a StatefulSet named `mysql`:
kubectl rollout restart statefulset/mysql
This command initiates a rolling update across the pods of the StatefulSet `mysql`.
5. Handling DaemonSets:
Restart all pods managed by a DaemonSet named `fluentd`:
kubectl rollout restart daemonset/fluentd
This command restarts all instances of the DaemonSet `fluentd`.
6. Viewing Rollout History:
List the revision history of a deployment:
kubectl rollout history deployment/myapp
This shows all revisions of the deployment `myapp`, including the current and previous versions.
7. Pausing and Resuming Rollouts:
Pause a deployment to prevent further updates:
kubectl rollout pause deployment/myapp
To resume the rollout, use:
kubectl rollout resume deployment/myapp
Pausing allows for investigation or manual intervention before continuing the rollout.
8. Force Rollout:
Forcefully roll out an update to a deployment:
kubectl rollout restart deployment/myapp --force
This command forcefully restarts all pods of the deployment `myapp`.
9. Monitoring Rollout Progress:
Watch the status of a rollout in real-time:
kubectl rollout status deployment/myapp --watch
This continuously monitors the deployment `myapp` until the rollout completes or encounters an error.
10. Editing Rollout Configuration:
Edit the configuration of a deployment and trigger a rollout:
kubectl set image deployment/myapp nginx=nginx:1.19
This updates the image of the `nginx` container in the deployment `myapp` to version `1.19`.
Verification: Check the rollout status or history to ensure the new image is applied successfully.
Also check similar articles.
Efficiently Delete Kubernetes Resources with kubectl delete
Comprehensive Guide to kubectl get Command
Understanding Kubernetes Resources with kubectl explain
Setting Features on Kubernetes Objects using kubectl set
Running Docker Images on Kubernetes with kubectl run
Discussion about this post