我们如何设置kubernetes以在推送新容器时自动更改容器? [英] How can we setup kubernetes to automatically change containers when a new one is pushed?

查看:74
本文介绍了我们如何设置kubernetes以在推送新容器时自动更改容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google云存储我的 Docker 图片和托管我的 kubernetes 集群.我想知道如何让 kubernetes 每次按下新容器时都拉下带有最新标签的容器.

I'm using google cloud to store my Docker images & host my kubernetes cluster. I'm wondering how I can have kubernetes pull down the container which has the latest tag each time a new one is pushed.

我认为 imagePullPolicy 是可行的方法,但似乎并没有完成任务(我可能会遗漏一些东西).这是我的容器规格:

I thought imagePullPolicy was the way to go, but it doesn't seem to be doing the job (I may be missing something). Here is my container spec:

"name": "blah",
"image": "gcr.io/project-id/container-name:latest",
"imagePullPolicy": "Always",
"env": [...]

目前,我必须在上载新的Docker映像时删除并重新创建部署.

At the moment I'm having to delete and recreate the deployments when I upload a new docker image.

推荐答案

Kubernetes本身不会在存储库中的容器映像更新时触发.您的工具中需要某种CI/CD管道.此外,我强烈建议避免使用:latest,因为它会使您的容器随时间变化.我认为使用某种版本控制会更好.就像image:1.4.3基于image:<gitsha>基于commit的语义一样,还是当我使用image:<gitsha>-<pushid>时,其中push是每次回购的推送的顺序更新值(因此即使我从同一版本重新上传,标签也会更改).

Kubernetes it self will never trigger on container image update in repository. You need some sort of CI/CD pipeline in your tooling. Furthermore, I do strongly advise to avoid using :latest as it makes your container change over time. It is much better in my opinion to use some sort of versioning. Be it semantic like image:1.4.3 commit based image:<gitsha> or as I use image:<gitsha>-<pushid> where push is a sequentially updated value for each push to repo (so that label changes even if I reupload from the same build).

使用这种版本控制,如果您更改清单中的映像,则部署将按预期进行滚动更新.

With such versioning, if you change image in your manifest, the deployment will get a rolling update as expected.

如果您要坚持使用image:latest,则可以在pod模板中添加带有版本的标签,因此如果碰碰它,它将滚动.您也可以手动一个接一个地杀死Pod,或者(如果可以承受宕机的话)可以将部署扩展到0个副本,然后再扩展回N

If you want to stick to image:latest, you can add a label with version to your pod template, so if you bump it, it will roll. You can also just kill pods manually one by one, or (if you can afford downtime) you can scale deployment to 0 replicas and back to N

这篇关于我们如何设置kubernetes以在推送新容器时自动更改容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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