0

I have three pods generated by a statefulset which are using outdated public docker images from docker hub.
I would like to update the images by changing the image entry in the statefulset yaml file.
What i have tried so far is kubectl -n THE_NAMESPACE apply -f statefuleset-definition.yaml after updating the file, i get: statefulset "statefulset-name" configured
But the pods will not automatically restart.
From this page i also see that is possible to pass an image name directly using the --image flag, but i would like this to happen from the statefulset definition file to keep both the file and the pods inline. This procedure also suggests adirect update but it will change the pod name which is something i dont want to.
Any tips?

JBoy
  • 5,398
  • 13
  • 61
  • 101

1 Answers1

0

You can use kubectl patch command to update your StatefulSet's image. By default it is using rolling update strategy to perform the statefulset's update.

It should be similar to:

kubectl patch statefulset <statefulset_name> --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"<new_image_name>"}]'

This way the image will be updated and pod names will be kept unchanged. It updates the pods one after another. If one pod receives an update, it patches next and so on. If the pod update has failed it will be restored to it's previous version.

kool
  • 3,214
  • 1
  • 10
  • 26