Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if Kubernetes deployment was sucessful in CI/CD pipeline

I have an AKS cluster with Kubernetes version 1.14.7.

I have build CI/CD pipelines to deploy newly created images to the cluster.

I am using kubectl apply to update a specific deployment with the new image. sometimes and for many reasons, the deployment fails, for example ImagePullBackOff.

is there a command to run after the kubectl apply command to check if the pod creation and deployment was successful?

like image 514
Johnny Zghaib Avatar asked Jan 18 '26 21:01

Johnny Zghaib


2 Answers

For this purpose Kubernetes has kubectl rollout and you should use option status.

By default 'rollout status' will watch the status of the latest rollout until it's done. If you don't want to wait for the rollout to finish then you can use --watch=false. Note that if a new rollout starts in-between, then 'rollout status' will continue watching the latest revision. If you want to pin to a specific revision and abort if it is rolled over by another revision, use --revision=N where N is the revision you need to watch for.

You can read the full description here

If you use kubect apply -f myapp.yaml and check rollout status you will see:

$ kubectl rollout status deployment myapp
Waiting for deployment "myapp" rollout to finish: 0 of 3 updated replicas are available…
Waiting for deployment "myapp" rollout to finish: 1 of 3 updated replicas are available…
Waiting for deployment "myapp" rollout to finish: 2 of 3 updated replicas are available…
deployment "myapp" successfully rolled out
like image 167
Crou Avatar answered Jan 20 '26 09:01

Crou


There is another way to wait for deployment to become available with a configured timeout like

kubectl wait --for=condition=available --timeout=60s deploy/myapp

otherwise kubectl rollout status can be used but it may stuck forever in some rare cases and will require manual cancellation of pipeline if that happens.

like image 40
Abdul Rauf Avatar answered Jan 20 '26 11:01

Abdul Rauf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!