我们可以将ConfigMap中定义的数据用作部署的密钥吗?

发布于 2025-01-24 08:11:52 字数 371 浏览 0 评论 0原文

我创建了一个configmap。我在configmap中添加了数据作为键值对,

data:
  EXTERNAL_CONFIG_FILE: /user/app/api/config

我需要使用此变量在部署中设置一个安装路径,

-  name: config-properties-volume-mnt
   mountPath: {{ $EXTERNAL_CONFIG_FILE }}

我在部署时会获得未定义的变量“ $ external_config_file”。 我不想在value.yaml中定义此变量。有没有办法在部署中使用ConfigMap中定义的此变量?

I have a configmap created. I have added data as a key-value pair in configmap

data:
  EXTERNAL_CONFIG_FILE: /user/app/api/config

I need to use this variable to set a mount path in deployment

-  name: config-properties-volume-mnt
   mountPath: {{ $EXTERNAL_CONFIG_FILE }}

I am getting undefined variable "$EXTERNAL_CONFIG_FILE" while deploying. I do not want to define this variable in values.yaml. Is there a way where I can use this variable defined in configmap in deployment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2025-01-31 08:11:52

不可能动态定义清单上的任何参数,您必须使用掌舵或kustomize

,否则您可以使用 sed 来替换文本在清单中,

您不能以这种方式使用这种方式, configmap secret 通常是将变量或文件注入pod,而不是在声明步骤中。

-  name: config-properties-volume-mnt
   mountPath: {{ $EXTERNAL_CONFIG_FILE }}

如果您有掌舵图表,将详细信息保留到vaules.yaml是唯一的选择。

subpath方法:

您可以使用子路口实现, subpath 您可以使用环境: https://kubernetes.io/docs/docs/concepts/concepts/storage/storage/volumes/#using-subpath-path-path-path-path-path-path-path-spath-eppand- expand- expand- expand- expanded-environment

apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  containers:
  - name: container1
    env:
    - name: EXTERNAL_CONFIG_FILE
      value: /user/app/api/config
    image: busybox:1.28
    command: [ "sh", "-c", "while [ true ]; do echo 'Hello'; sleep 10; done | tee -a /logs/hello.txt" ]
    volumeMounts:
    - name: workdir1
      mountPath: /logs
      # The variable expansion uses round brackets (not curly brackets).
      subPathExpr: $(EXTERNAL_CONFIG_FILE)
  restartPolicy: Never
  volumes:
  - name: workdir1
    hostPath:
      path: /var/log/pods

env 在上面示例中使用的您可以使用 configmap

It's not possible to dynamically define any parameter on a manifest, you have to use the Helm or Kustomize

Or else you can use the sed to replace the Text in manifest simply

You can not use this way, configmap and secret are normally to inject the variables or file into the POD not at declare step.

-  name: config-properties-volume-mnt
   mountPath: {{ $EXTERNAL_CONFIG_FILE }}

if you have helm chart keeping details into the vaules.yaml is the only option.

Subpath method :

You can use the subpath to achieve, with subpath you can use the environment: https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath-expanded-environment

apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  containers:
  - name: container1
    env:
    - name: EXTERNAL_CONFIG_FILE
      value: /user/app/api/config
    image: busybox:1.28
    command: [ "sh", "-c", "while [ true ]; do echo 'Hello'; sleep 10; done | tee -a /logs/hello.txt" ]
    volumeMounts:
    - name: workdir1
      mountPath: /logs
      # The variable expansion uses round brackets (not curly brackets).
      subPathExpr: $(EXTERNAL_CONFIG_FILE)
  restartPolicy: Never
  volumes:
  - name: workdir1
    hostPath:
      path: /var/log/pods

Instead of env used in the above example you can use the configmap

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文