Skip to main content
1 of 3

Passing ENV VAR via ConfigMap does not work

apiVersion: v1
kind: ConfigMap
metadata:
  name: time-config
data:
  TIME_FREQ: 6
---
apiVersion: v1
kind: Pod
metadata:
  name: time-check
spec:
  containers:
  - name: time-check
    image: busybox:latest
    command: ["/bin/sh"]
    args: ["-c","while true; do date; sleep $TIME_FREQ;done >> /opt/data/time/time-check.log"]
    env:
      - name: TIME_FREQ
        valueFrom:
          configMapKeyRef:
            name: time-config
            key: TIME_FREQ
    volumeMounts:
      - name: log-volume
        mountPath: /opt/data/time
  volumes:
  - name: log-volume
    emptyDir: {}

According to documentation, to use variable you should put it in parentheses, however, that gives me:

TIME_FREQ: command not found
sleep: missing operand

If I use only $TIME_FREQ, the variable does not expand at all and sleep only complains about missing operand. I've tried curly braces, but didn't work, too.

If I set the variable locally, the config will accept it and the command runs ok, with variable defined as $TIME_FREQ.

Why does it not work?