【问题标题】:How to kubectl re-apply deploymentHow to kubectl re-apply deployment
【发布时间】:2022-12-27 22:19:28
【问题描述】:

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

【问题讨论】:

  • kubectl rollout restart deployment/xxx?

标签: kubernetes kubectl


【解决方案1】:

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 toalwaysin your deployment.yaml

Or else you need to update one minor field into deployment.yaml and keep imagePullPolicy toalwaysin 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?

【讨论】:

    【解决方案2】:

    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.

    【讨论】:

      猜你喜欢
      • 2022-12-02
      • 2022-12-02
      • 2022-12-02
      • 2018-05-02
      • 2018-06-14
      • 1970-01-01
      • 2023-01-06
      • 2019-03-01
      • 2018-04-24
      相关资源
      最近更新 更多