I am setting up an application in kubernetes and want to restart the pod if the new image is pushed into docker hub. I am not able to restart the pod if the new image is pushed into docker hub registry?
I have included
"imagePullPolicy": "Always"
"terminationGracePeriodSeconds": 30
in deployment.yaml file
How to pull the new image to pod without stopping the existing pod?
A pod launched is immutable, if you make a image change in a deployment it will change only when the new containers are launched and the old ones deleted.
Use deployments to launch your pods. Launch the following command to change the image:
kubectl set image deployment/DEPLOY_NAME container-name=image_path:version
The deploy will take care of killing the old pods and launching new ones.
Even in plain Docker, you can never update a container to a newer image without deleting and recreating it. This is also impossible in Kubernetes: the list of containers
in a pod spec “cannot currently be added or removed...cannot be updated”, which means you can never change the image on an existing Pod.
In Kubernetes, the best practice is to always use an explicit version tag (never latest
or anything similar that’s expected to change) and to manage Pods with Deployments. When you have a new build, change your Deployment spec to have the new tag. Kubernetes will notice that the new Deployment is different from the old one, and will, in order:
This results in a zero-downtime upgrade.