Kubernetes部署的最佳CD策略 [英] Best CD strategy for Kubernetes Deployments
问题描述
我们当前的CI部署阶段是这样的:
Our current CI deployment phase works like this:
- 构建容器.
- 将图像标记为
"latest"
和< commit hash >
. - 将图像推送到存储库.
- 在适当的RC上调用滚动更新.
- Build the containers.
- Tag the images as
"latest"
and< commit hash >
. - Push images to repository.
- Invoke rolling update on appropriate RC(s).
这对于基于RC的部署一直非常有效,但是现在Deployment
对象变得更加稳定并且具有基础功能,我们希望在我们当前的部署方案和开发阶段中利用这种抽象.
This has been working great for RC based deployments, but now that the Deployment
object is becoming more stable and an underlying feature, we want to take advantage of this abstraction over our current deployment schemes and development phases.
我遇到的麻烦是找到一种合理的方法来自动执行CI工作流程中Deployment
的更新.我一直在尝试的是拆分git repo并做类似的事情:
What I'm having trouble with is finding a sane way to automate the update of a Deployment
with the CI workflow. What I've been experimenting with is splitting up the git repo's and doing something like:
- [App Build]构建容器.
- [App Build]将图像标记为
"latest"
和< commit hash >
. - [App Build]将图像推送到存储库.
- [App Build]调用应用程序
Deployment
存储库的构建,并通过当前提交哈希进行传递. - [Deployment Build]插入清单文件令牌(当前仅是传递的提交哈希,例如
image: app-%%COMMIT_HASH%%
) - [部署构建]将更新的清单应用于适当的
Deployment
资源.
- [App Build] Build the containers.
- [App Build] Tag the images as
"latest"
and< commit hash >
. - [App Build] Push images to repository.
- [App Build] Invoke build of the app's
Deployment
repo, passing through the current commit hash. - [Deployment Build] Interpolate manifest file tokens (currently just the passed commit hash e.g.
image: app-%%COMMIT_HASH%%
) - [Deployment Build] Apply the updated manifest to the appropriate
Deployment
resource(s).
当然,有更好的方法可以解决此问题.如果Deployment
监视图像的最新"标签的哈希变化会很好...也许已经这样做了?我还没有成功.关于如何更好地处理Deployment
部署的任何想法或见解,将不胜感激:)
Surely though there's a better way to handle this. It would be great if the Deployment
monitored for hash changes of the image's "latest" tag...maybe it already does? I haven't had success with this. Any thoughts or insights on how to better handle the deployment of Deployment
would be appreciated :)
推荐答案
Deployment
仅监视pod模板(.spec.template
)的更改.如果图像名称未更改,则Deployment
不会进行更新.您可以通过更改pod模板来触发滚动更新(使用Deployment
),例如,使用commit hash对其进行标记.另外,您需要将.spec.template.spec.containers.imagePullPolicy
设置为Always
(如果指定了:latest
标记且无法更新,则默认将其设置为Always
),否则图像将被重用.
The Deployment
only monitors for pod template (.spec.template
) changes. If the image name didn't change, the Deployment
won't do the update. You can trigger the rolling update (with Deployment
s) by changing the pod template, for example, label it with commit hash. Also, you'll need to set .spec.template.spec.containers.imagePullPolicy
to Always
(it's set to Always
by default if :latest
tag is specified and cannot be update), otherwise the image will be reused.
这篇关于Kubernetes部署的最佳CD策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!