I'm trying to bootstrap a etcd cluster within my kubernetes cluster, here is the relevant section of the pod definition
- name: etcd
image: quay.io/coreos/etcd:v2.2.0
ports:
- containerPort: 2379
- containerPort: 2380
- containerPort: 4001
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
args:
- "-name"
- "etcd0"
- "-advertise-client-urls"
- http://${POD_IP}:2379,http://${POD_IP}:4001
- "-initial-advertise-peer-urls"
- "http://${POD_IP}:2380"
- "-listen-peer-urls"
- "http://0.0.0.0:2380"
- "-initial-cluster"
- 'etcd0=http://${POD_IP}:2380'
- "-initial-cluster-state"
- "new"
However when I apply the POD_IP environment variable seems to get mangled, evidenced by the log:
advertise URLs of "etcd0" do not match in --initial-advertise-peer-urls [http://$%7BPOD_IP%7D:2380] and --initial-cluster [http://$%7BPOD_IP%7D:2380]
Has anyone seen anything similar to this?
The arguments are not interpreted by a shell, so curly braces don't get you the behavior you want. If you want to use an envvar value in an arg, variable references like $(VAR_NAME)
are expanded using the container's environment.
Init containers use cases:
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
Place values into a configuration file and run a template tool to dynamically generate a configuration file for the main app Container. For example, place the POD_IP value in a configuration and generate the main app configuration file using Jinja