如何在 Kubernetes 中获取动态键的 configmap 值
在我的一个部署文件中,我想设置一个环境变量。该变量是 KUBE_VERSION ,并且必须从 ConfigMap 中获取值。
kube_1_21: 1.21.10_1550
这是 ConfigMap 的一部分,我想将 1.21.10_1550
设置为 KUBE_VERSION
,但如果集群是 IKS 1.20,则密钥将为:
kube_1_20: 1.20.21_3456
kube_< /code> 始终是静态的。如何使用正则表达式设置环境变量?
类似这样的事情:
- name: KUBE_VERSION
valueFrom:
configMapKeyRef:
name: cluster-info
key: "kube_1*"
In one of my deployment files, I want to set an environment variable. The variable is KUBE_VERSION
and values must be fetched from a ConfigMap.
kube_1_21: 1.21.10_1550
This is part of ConfigMap where I want to set 1.21.10_1550
to KUBE_VERSION
, but if the cluster is of IKS 1.20, then the key will be:
kube_1_20: 1.20.21_3456
kube_
is always static. How can I set environment variable using a regex expression?
Something of this sort:
- name: KUBE_VERSION
valueFrom:
configMapKeyRef:
name: cluster-info
key: "kube_1*"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,不幸的是不可能按照您的意愿使用正则表达式。此外,您还可以获得有关验证输入数据的正则表达式的信息:
因此,您必须输入
key
作为字母数字字符串,此外您还可以使用字符-
、_
和.
所以在这个地方不可能使用正则表达式。要解决此问题,您可以在 Bash 中编写自定义脚本,并将正确的行替换为 sed 命令。
As far as I know it is unfortunately not possible to use the regular expression as you would like. Additionally, you have information about the regular expression that validates the entered data:
It follows that you have to enter
key
as an alphanumeric string and additionally you can use the characters-
,_
and.
So it is not possible to use regex in this place.To workaround you can write your custom script i.e. in Bash and replace the proper line with sed command.