You can populate Kubernetes Pods with environment variables either individually (env) or all in one go (envFrom). Prefer envFrom as it makes things very easy and clean.


Example


configmap.yaml


apiVersion: v1
kind: ConfigMap

metadata:
name: address-finder-config

data:
VERSION: ""
HTTP_ADDRESS: :8888
LOG_LEVEL: info
# version: ""
# http_address: :8888
# log_level: info

deployment.yaml


apiVersion: apps/v1
kind: Deployment

metadata:
name: address-finder-deployment
labels:
app: address-finder

spec:
replicas: 1
selector:
matchLabels:
app: address-finder
template:
metadata:
labels:
app: address-finder
spec:
containers:
- name: golang
image: you/address-finder:latest
envFrom:
- configMapRef:
name: address-finder-config
# env:
# - name: VERSION
# valueFrom:
# configMapKeyRef:
# name: address-finder-config
# key: version
# - name: HTTP_ADDRESS
# valueFrom:
# configMapKeyRef:
# name: address-finder-config
# key: http_address
# - name: LOG_LEVEL
# valueFrom:
# configMapKeyRef:
# name: address-finder-config
# key: log_level