Once you've prepared your Kubernetes environment for a rolling restart, you can use the kubectl
command-line tool to perform the actual rolling update.
Update the Deployment's Container Image
To perform a rolling restart, you'll need to update the container image used by your deployment. You can do this using the kubectl set image
command. For example:
kubectl set image deployment/my-app app=labex/my-app:v2
This command will update the container image for the app
container in the my-app
deployment to the labex/my-app:v2
image.
Monitor the Rolling Restart Process
After updating the container image, Kubernetes will automatically begin the rolling restart process. You can monitor the progress of the rolling restart using the kubectl rollout status
command:
kubectl rollout status deployment/my-app
This command will output the current status of the rolling restart, including the number of old and new pods, and the overall progress of the update.
Verify the Deployment Update
Once the rolling restart is complete, you can verify that the new version of your application is running by checking the pods in your deployment:
kubectl get pods -l app=my-app
This command will list all the pods in the my-app
deployment, and you should see that the container image has been updated to the new version.
Rollback the Deployment (if Necessary)
If you encounter any issues during the rolling restart, you can rollback to the previous version of your deployment using the kubectl rollout undo
command:
kubectl rollout undo deployment/my-app
This command will roll back the deployment to the previous version, ensuring that your application remains available and stable.
By using the kubectl
command-line tool, you can easily perform a Kubernetes rolling restart and monitor the update process. This allows you to update your application with minimal downtime and disruption to your users.