0
votes

I have a Pod - I want to update to latest version of container image, if it fails then want to revert it back to earlier version of container image.

Which approach of below will be good to update to latest or earlier container image. 1> using kubectl patch is good option? 2> deleting the pod and again creating the pod is good option?

what are benefits/disadvantages of both approach.

kubectl patch pod test-pod -p '{"spec":{"containers":[{"name":"test","image":"1.0"}]}}'

kubectl delete pod test-pod and kubectl apply -f testpod.yaml

2

2 Answers

1
votes

based on the scenario put up by you, you can choose to look for doing canary deployments by using the rolling update strategy, if the new deployment's containers fail to serve the load then the old ones will not be destroyed and load will continuously be served by pre-existing containers.

The other way can be to keep deployment history, you can define the number of manifests you want to be saved by kubernetes and then you can manually rollback to your desired version

And if you are not aware about what version carries which image then you can go for patch command, as portrayed by you in the question

1
votes

From the docs here one of the use cases of deployment

Rollback to an earlier Deployment revision if the current state of the Deployment is not stable. Each rollback updates the revision of the Deployment.

So use deployment to perform rolling update and rollback when necessary

kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.161 --record=true

Check rollout history

kubectl rollout history deployment.v1.apps/nginx-deployment

Rollback to a previous version

kubectl rollout undo deployment.v1.apps/nginx-deployment