John
John

Reputation: 1347

How to kubectl re-apply deployment

I want to update my pod because there is a new image uploaded to docker registry with latest tag.

I am currently doing this:

kubectl delete -f deployment.yaml
kubectl apply -f deployment.yaml

If I do:

kubectl apply -f deployment.yaml

It says my deployment is unchanged.

However, I want make my service alive even for a second. Isn't there a way I could do something like the following?

kubectl re-apply -f deployment.yaml

Upvotes: 11

Views: 21945

Answers (2)

dhruvinrsoni
dhruvinrsoni

Reputation: 39

The below command will do a rolling restart of your deployment even if the whole yaml is same and it says unchanged.

kubectl rollout restart -f deploy.yaml --selector=component=deploy

Here the trick is that we need to add additional label of component: deploy to the metadata of the deployment type so that it selectively only restarts the deployment only. This will add up as additional config update as well as one more command but will do the needful.

Upvotes: 3

Harsh Manvar
Harsh Manvar

Reputation: 30160

You can just delete the POD once and restart the POD so it will change the image and pull new version from docker registry.

However, make sure imagePullPolicy set to always in your deployment.yaml

Or else you need to update one minor field into deployment.yaml and keep imagePullPolicy to always in that case apply will change the deployment.

Example :

spec:
  containers:
  - name: test
    image: image:latest
    ports:
    - containerPort: 80
    imagePullPolicy: Always
  imagePullSecrets:
    - name: docker-secret

Option 2

kubectl rollout restart deployment/<deployment-name>

Read more at : How do I force Kubernetes to re-pull an image?

Upvotes: 14

Related Questions