google-cloud-platform - 在 GCP 中,如何在容器 k8s 集群中添加标签,而不是更新?
问题描述
我正在尝试添加标签k8s cluster
,但不幸的是它删除了所有添加的新标签。
gcloud container clusters update example-cluster --zone us-west1-a --update-labels env=dev
我想在现有集群中添加标签(保留以前的标签)。有没有办法做到这一点?
谢谢
解决方案
因此,我在自动化创建中添加了几行 python 代码来解决上述问题。
cmd = "gcloud container clusters list --format='json(name,status,zone,resourceLabels)'"
a = { "container" : json.loads(subprocess.check_output(shlex.split(cmd)))}
labels = a['container'][0]['resourceLabels']
labels["name"]= a['container'][0]['name'] #Adding new label
new_labels = (str(labels).replace("{","").replace("}", "").replace(" ", "").replace(":", "=").replace("'", ""))
CMD = "gcloud container clusters update {0} --zone {1} --project {2} --update-labels {3} ".format(rname, zone, PROJECTID, labels)
subprocess.call(CMD, shell=True)
推荐阅读
- node.js - Puppeteer/Playwright 是否可以将浏览器设置为无头启动时可见
- mithril.js - 为什么秘银子组件状态改变不触发更新?
- javascript - 需要帮助将变量设置为 false 并且按键为 true,但中间有足够的时间来实现对象
- mysql - Node.js 中 MySQL 的结果与终端不同
- swift - 如何在 Swift 中使用 Vision 或 AVFoundation 自动检测人脸并自拍?
- c# - C# WinForms - 如何防止自定义控件继承表单字体样式?
- jupyter-notebook - Jupyter Server 和 Anaconda 之间的 Tornado 版本冲突?
- python - 使用python循环运行密码验证时遇到问题
- c++ - 如何使纯虚函数在父类函数中工作
- r - RStudio 中的处理