Sunday 7 February 2021

Getting rollout status of Kubernetes Deployment object

With kubectl rollout status deployment deployment-name, you can check the rollout status of a Kubernetes Deployment deployment-name. If the rollout completes successfully, kubectl rollout status returns a zero exit code otherwise a non-zero exit code is returned.

Assuming, we have a Deployment name app with three replicas and we updated the Deployment with a new image.

Running the kubectl rollout status deployment/app will show the following output if the pods get updated without errors:

kubectl rollout status deployment app
Waiting for deployment "app" rollout to finish: 0 of 3 updated replicas are available…
Waiting for deployment "app" rollout to finish: 1 of 3 updated replicas are available…
Waiting for deployment "app" rollout to finish: 2 of 3 updated replicas are available…
deployment "app" successfully rolled out

We can also specify how long Kubernetes should wait for deployment to progress until it declares the rollout as a failure. Kubernetes marks the deployment status as failed if the deployment doesn't succeed until the deadline is met which the rollout status command uses to return its output.

We see logs similar to the below logs for a failed rollout:

kubectl rollout status deployment app
Waiting for deployment "app" rollout to finish: 1 out of 3 new replicas have been updated…
error: deployment "app" exceeded its progress deadline
Using the above concepts, the answers to your questions will be:

How to make sure the new deployment succeed?

kubectl rollout status deployment <deployment-name> will return with zero exit code which you can use to verify that the deployment was successful.

How to make the the new deployment failed?

kubectl rollout status deployment <deployment-name> will return with non-zero exit code which you can use to verify that the deployment has failed.

Is it safe to assume that if the spec/containers/0/image changes to something different than what I'm expecting, it means there is a new deployment and I should stop watching?

Kubernetes does not create a new Deployment object after the modification but it updates the existing one with the new changes. Deployment internally creates a new ReplicaSet object which creates new set of pods for rolling out new changes. You can use the same kubectl rollout status deployment <deployment-name> command to track the status of the new Deployment.

Share:

Contact Me

Name

Email *

Message *

Popular Posts