If i have a pod with nginx image , i saves its yaml to disk, edit the yaml and e . . .

Puneet Khanna:
if i have a pod with nginx image , i saves its yaml to disk, edit the yaml and edit the image to ubuntu , how does the pod change the image without restarting it ? as it says that we can change the image container for an already running pod ?

Pete Wall:
https://kubernetes.io/docs/concepts/workloads/pods/#pod-update-and-replacement

Pete Wall:
That’s a good question. I’m looking into it.

Pete Wall:
So, just tried this on a cluster. When changing the container image, it stops the existing container, pulls the new image and starts a new container.

So, the pod stays running, but the underlying container does not.

Pete Wall:
They probably support this to make it easier to do something like:

spec:
  containers:
    - image: myimage:1.0.0

edit and save as:

spec:
  containers:
    - image: myimage:1.0.1

Puneet Khanna:
Did you use kubectl edit --force, or kubectl edit ot kubectl apply -f --force

Puneet Khanna:
Then below statement is very confusing, a pod running could only help if you have two containers , and you just update 1 of them , the 2second container remians running without a hindrance?

Pod updates may not change fields other than spec.containers[*].image

Puneet Khanna:
@Pete Wall i changed the image with kubectl edit pod {podname} and found from kubectl get events that the pod or container gets killed and container is restarted

707ms
9m25s       Normal    Created                   pod/puneet           Created container puneet
9m25s       Normal    Started                   pod/puneet           Started container puneet
7m12s       Normal    Pulling                   pod/puneet           Pulling image "ubuntu"
34s         Normal    Killing                   pod/puneet           Container puneet definition changed, will be restarted

Sergei Diachenko:
@Puneet Khanna you cannot change pod spec without restarting it. Whenever you change image in the pod spec, old pod is deleted and new pod is created.

Puneet Khanna:
Thanks Sergei for help, i see that the pod attributes remain in etcd when i issue kubectl describe and the container is restarted instead but pod remains . Can you try it again when you get a moment, i am slightly confused to be very honest with the documentation

Sergei Diachenko:
@Puneet Khanna you are right, if you update spec inside pod, it remains but restarted. This is right in the case when you create pod directly without controllers.
If controllers (deployment, statefulset, job etc) create pods for you, they delete pod and create new one when you update template in controller spec.

Puneet Khanna:
Thanks Sergei, i appreciate that people take time to help each other here