Can we read environment variable on Azure Kubernetes Pod?
To access env from k8s pods, you need to provide those env through pod's spec.containers[].env[]
.
apiVersion: v1kind: Podmetadata: name: demo-podspec: containers: - name: mycontainer image: demo/new-image env: # define env from k8s secret (used specially for credentials) - name: SECRET_USERNAME valueFrom: secretKeyRef: name: mysecret key: username # define env from configmap - name: SPECIAL_CREDENTIALS valueFrom: configMapKeyRef: name: configmap-name key: config.json # define value directly - name: DEMO_GREETING value: "Hello from the environment"
If you want to pass the environment variable to code you can use the value of config map
of kubernetes. it will set the value in environment os of pod and in code you can get it from there.
for secure data you can use the secret
.