String operation on env variables on Kubernetes

You can do something like

- name: MY_POD_NAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.name
- name: MY_POD_URI
  value: "uri://$(MY_POD_NAME):9099/"

We are using that since K8s 1.4

$() is processed by k8s itself, does not work everywhere, but works for env variables.

If your container contains bash, you can also leverage bash variable expansion

"command": ["/bin/bash"],
"args": [ "-c",
         "MY_POD_URI_BASH=uri://${MY_POD_NAME}:9099/ originalEntryPoint.sh
       ],

${} is not touched by k8s, but evaluated later in container by bash. If you have a chance, prefer the first option with $()

note: order matters in declaration. In example above, if MY_POD_NAME is defined later in env array, the expansion will not work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)