codependent
codependent

Reputation: 24472

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:

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, e.g.:

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.

Upvotes: 0

Views: 165

Answers (1)

Anton Matsiuk
Anton Matsiuk

Reputation: 690

in your case it won't work since you define data as application.properties file. It needs to be key:value maps, see here

in your case:

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

Upvotes: 1

Related Questions