How to pull the new image to kubernetes from docker hub without effecting the running pod?

3/25/2019

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?

-- rakeshh92
docker
docker-compose
kubernetes

2 Answers

3/25/2019

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.

-- Leandro Donizetti Soares
Source: StackOverflow

3/25/2019

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:

  1. Start a new Pod with the new image;
  2. Wait for its health checks to pass; and
  3. Delete the old Pod.

This results in a zero-downtime upgrade.

-- David Maze
Source: StackOverflow