重新部署最新映像而不使用`kubectl apply -f file`

时间:2019-06-27 01:44:18

标签: kubectl amazon-eks aws-eks eks

我们在集群上进行了部署,我们想告诉它拉最新的映像并重新部署。如果我运行kubectl apply -f deployment.yml,则该文件实际上没有更改。我如何告诉集群使用更新的映像版本?

1 个答案:

答案 0 :(得分:1)

根据文档:

  

注意:仅当更改部署的pod模板(即.spec.template)(例如,模板的标签或容器图像已更新)时,才会触发部署的推出。其他更新(例如扩展Deployment)不会触发部署。

请考虑使用:

kubectl patch deployment my-nginx --patch '{"spec": {"template": {"spec": {"containers": [{"name": "nginx","image": "nginx:1.7.9"}]}}}}'

kubectl --record deployment.apps/nginx-deployment set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1

kubectl edit deploy/<your_deployment> --record

有关Updating a DeploymentContainer Images的文档。

根据最佳做法,请注意:

  

在生产环境中部署容器时,应避免使用:latest 标记,因为更难跟踪正在运行哪个版本的映像,并且更难正确回滚。

但是,如果您希望始终强制拉出新图像,则可以在those options上使用:

   - set the imagePullPolicy of the container to Always.
   - omit the imagePullPolicy and use :latest as the tag for the image to use.
   - omit the imagePullPolicy and the tag for the image to use.
   - enable the AlwaysPullImages admission controller.

希望获得帮助。