I am working on a kodekloud excercise (Example 2) where I need to expand a variable, but it doesn’t work any way I tried. The “kubernetes” expansion results with VAR: command not found
, and normal expansions $VAR or ${VAR} result with empty string, although the variable is loaded inside the container. Apart from kodekloud environment, I am testing this also in latest stable minikube.
Why does it not work?
Example 1
apiVersion: v1
kind: Pod
metadata:
name: echo
spec:
containers:
- name: busy-echo
image: busybox:latest
env:
- name: MESSAGE
value: "hello world"
command: ["/bin/echo"]
args: ["$(MESSAGE)"]
Example 2
apiVersion: v1
kind: ConfigMap
metadata:
name: time-config
data:
TIME_FREQ: "4"
---
apiVersion: v1
kind: Pod
metadata:
name: time-check
spec:
containers:
- name: time-check
image: busybox:latest
command: ["/bin/sh","-c"]
args: ["while true; do date; sleep $TIME_FREQ; done"]
env:
- name: TIME_FREQ
valueFrom:
configMapKeyRef:
name: time-config
key: TIME_FREQ