Kubernetes部署的最佳CD策略 [英] Best CD strategy for Kubernetes Deployments

查看:145
本文介绍了Kubernetes部署的最佳CD策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前的CI部署阶段是这样的:

Our current CI deployment phase works like this:

  1. 构建容器.
  2. 将图像标记为"latest"< commit hash >.
  3. 将图像推送到存储库.
  4. 在适当的RC上调用滚动更新.
  1. Build the containers.
  2. Tag the images as "latest" and < commit hash >.
  3. Push images to repository.
  4. 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:

  1. [App Build]构建容器.
  2. [App Build]将图像标记为"latest"< commit hash >.
  3. [App Build]将图像推送到存储库.
  4. [App Build]调用应用程序Deployment存储库的构建,并通过当前提交哈希进行传递.
  5. [Deployment Build]插入清单文件令牌(当前仅是传递的提交哈希,例如image: app-%%COMMIT_HASH%%)
  6. [部署构建]将更新的清单应用于适当的Deployment资源.
  1. [App Build] Build the containers.
  2. [App Build] Tag the images as "latest" and < commit hash >.
  3. [App Build] Push images to repository.
  4. [App Build] Invoke build of the app's Deployment repo, passing through the current commit hash.
  5. [Deployment Build] Interpolate manifest file tokens (currently just the passed commit hash e.g. image: app-%%COMMIT_HASH%%)
  6. [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 Deployments) 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆