Specify default values for env variables that get populated from ConfigMap/Secret/etc

At the moment, I have defined a few environment variables whose values should be set from specific keys in the config map. However, I want to add default values to these environment variables in case the key isn’t present in config map. What is the recommended method for specifying default values for environment variables in container spec? At the moment, I am doing the following

env:
  - name: MY_VAR
    value: default
  - name: MY_VAR
    valueFrom:
      configMapKeyRef:
        name: myconfig
        key: my_var
        optional: true

Cluster information:

Kubernetes version: 1.14.8
Cloud being used: Azure
Installation method: Azure Kubernetes Service
Host OS: Ubuntu 16.04

Hi Partha,
You can try using initContainers to setup the default values when configMap does not or miss the env variables defined for your application.
Please let me know if this works for you.