How to kubectl re-apply deployment

Viewed 1042

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
1 Answers

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?

Related