简体   繁体   English

有没有办法从文件创建的 configmap 在 pod 中配置环境变量?

[英]Is there a way to configure environment variables in a pod from a configmap created from a file?

I have a config map that was created from an application.properties file:我有一个从 application.properties 文件创建的配置 map:

apiVersion: v1
data:
  application.properties: |-
    datasource-url: xxx
    web-service-url: https://xxx
kind: ConfigMap
  name: my-configmap
  namespace: mynamespace

I would like to create environment variables from some of those values, eg:我想从其中一些值创建环境变量,例如:

spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      env:
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            configMapKeyRef:
              name: my-configmap
              key: datasource-url

However this doesn't work, it can't access the datasource-url property from the file.但是这不起作用,它无法从文件中访问 datasource-url 属性。

in your case it won't work since you define data as application.properties file.在您的情况下,它将不起作用,因为您将数据定义为application.properties文件。 It needs to be key:value maps, see here它需要是key:value映射,请参见此处

in your case:在你的情况下:

apiVersion: v1
data:
  datasource-url: xxx
  web-service-url: https://xxx
kind: ConfigMap
  name: my-configmap
  namespace: mynamespace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM