kubectl - 重新部署最新镜像而不使用`kubectl apply -f file`
问题描述
我们在集群上进行了部署,我们想告诉它提取最新的映像并重新部署。如果我运行kubectl apply -f deployment.yml
该文件实际上并没有改变。我如何告诉集群使用更新的映像版本?
解决方案
根据文档:
注意:当且仅当 Deployment 的 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
根据最佳实践,请注意:
在生产环境中部署容器时,您应该避免使用:latest标签,因为很难跟踪哪个版本的映像正在运行并且更难以正确回滚。
但是,如果您想始终强制拉新图像,您可以使用这些选项:
- 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.
希望这有帮助。
推荐阅读
- boto3 - Boto3 显示了这么多 ec2 快照,没有一个快照不属于我
- javascript - 如何使用带有define()的js库和js库作为ES6模块?
- typescript - 扩展中的 CompletionProvider Intellisense 仅适用于特定符号“:”,不适用于点符号“。”
- css - 为什么边距用于粘性定位
- java - 从java中的cmd命令获取输出
- visual-studio-code - Prettier 在 VS Code 中停止工作 - 错误“未提供配置”
- ios - Alamofire 4 - 使用 gzip 编码上传多部分
- c# - 用 C# 替换 EXCEL 文件中的所有换行符
- python - 使用正则表达式查找“4 月 24 日”或“12 月 18 日”格式的日期
- angular - 订阅服务主题时 NgFor 不工作