如何一次编辑所有的Kubernetes部署 [英] How to edit all the deployment of kubernetes at a time

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

问题描述

我们有数百个部署,并且在配置中,对于大多数部署,我们将imagePullPolicy设置为"ifnotpresent",很少将其设置为"always",现在我要修改所有具有 ifnotpresent 的部署>始终 .

We have hundreds of deployment and in the config we have imagePullPolicy set as "ifnotpresent" for most of them and for few it is set to "always" now I want to modify all deployment which has ifnotpresent to always.

我们如何一口气做到这一点?

How can we achieve this with at a stroke?

例如:

kubectl get deployment -n test -o json | jq ‘.spec.template.spec.contianer[0].imagePullPolicy="ifnotpresent"| kubectl -n test replace -f - 

以上命令有助于将其重置为一种特定的部署.

The above command helps to reset it for one particular deployment.

推荐答案

Kubernetes本身不提供大规模更新功能.为此,您必须使用其他CLI工具.话虽如此,对于修改现有资源,您还可以使用kubectl patch函数.

Kubernetes doesn't natively offer mass update capabilities. For that you'd have to use other CLI tools. That being said, for modifying existing resources, you can also use the kubectl patch function.

下面的脚本并不漂亮,但是会更新名称空间中的所有部署.

The script below isn't pretty, but will update all deployments in the namespace.

kubectl get deployments -o name | sed -e 's/.*\///g' | xargs -I {} kubectl patch deployment {} --type=json -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/imagePullPolicy", "value": "Always"}]'

注意:我用sed从名称中剥离了资源类型,因为kubectl无法识别对deployment.extensions类型的资源(可能还有其他)执行的操作.

Note: I used sed to strip the resource type from the name as kubectl doesn't recognize operations performed on resources of type deployment.extensions (and probably others).

这篇关于如何一次编辑所有的Kubernetes部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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