0
votes

I'm running GKE cluster and there is a deployment that uses image which I push to Container Registry on GCP, issue is - even though I build the image and push it with latest tag, the deployment keeps on creating new pods with the old one cached - is there a way to update it without re-deploying (aka without destroying it first)?

There is a known issue with the kubernetes that even if you change configmaps the old config remains and you can either redeploy or workaround with

kubectl patch deployment $deployment -n $ns -p \
  "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"

is there something similar with cached images?

2
By something similar you mean if there is something like kubectl patch deployment to update deployment image instead of deleting it and creating again from new yaml?Jakub
yup exactly, same goes for resources limits/requests - once you create a deployment u cannot upgrade its resources unless re-deployed - I'm looking for the latter solution how to do it with commands - update image and update resources, if you know answer to any i'd appreciate itCptDolphin

2 Answers

1
votes

I think you're looking for kubectl set or patch which I found there in kubernetes documentation.

To update image of deployment you can use kubectl set

kubectl set image deployment/name_of_deployment name_of_deployment=image:name_of_image

To update image of your pod you can use kubectl patch

kubectl patch pod name_of_pod  -p '{"spec":{"containers":[{"name":"name_of_pod_from_yaml","image":"name_of_image"}]}}'

You can always use kubectl edit to edit which allows you to directly edit any API resource you can retrieve via the command line tool.

kubectl edit deployment name_of_deployment

Let me know if you have any more questions.

1
votes

1) You should change the way of your thinking. Destroying pod is not bad. Application downtime is what is bad. You should always plan your deployments in such a way that it can tolerate one pod death. Use multiple replicas for stateless apps and use clusters for stateful apps. Use Kubernetes rolling update for any changes to your deployments. Rolling updates have many extremely important settings which directly influence the uptime of your apps. Read it carefully.

2) The reason why Kubernetes launches old image is that by default it uses imagePullPolicy: IfNotPresent. Use imagePullPolicy: Always and it will always try to pull latest version on redeploy.