Environment Variables
Manage environment variables cleanly in ohMyHelm using staticEnv, env, extraEnv, and envFrom across the main container, sidecar, init container, and jobs.
Environment Variables
ohMyHelm splits environment variables into three separate lists (staticEnv, env, extraEnv) plus envFrom. This pattern is consistently available for chart.container, chart.sidecar, chart.initContainer, chart.job, and the standalone job helper.
Why Three Separate Lists? (The List-Merge Concept)
When layering multiple values files (-f values.yaml -f values-prod.yaml), Helm does not merge YAML lists (arrays); instead, it replaces the entire list. If there were only a single env list, every environment file would have to repeat all baseline variables.
ohMyHelm solves this by concatenating all three lists in a fixed order under env: inside the templates:
staticEnv— Constant baseline variables andsecretKeyRef/configMapKeyRefbindings stored in the basevalues.yamlthat stay identical across all environments.env— Environment-specific variables (such asAPP_ENV, API URLs, or feature flags) that you set per stage invalues-dev.yamlorvalues-prod.yaml.extraEnv— Optional ad-hoc overrides, for instance temporary debug flags or CI/CD overrides, without touchingstaticEnvorenv.
In addition, envFrom loads entire ConfigMaps or Secrets at once as environment variables via configMapRef and secretRef.
Example: Main Container with All Four Fields
chart:
enabled: true
fullnameOverride: "acme-backend"
container:
image: registry.acme.corp/backend:2.0.0
ports:
- name: http
containerPort: 8080
# 1. Constant baseline variables (in values.yaml)
staticEnv:
- name: APP_NAME
value: acme-backend
- name: DATABASE_USER
valueFrom:
secretKeyRef:
name: acme-db-credentials
key: username
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: acme-db-credentials
key: password
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
# 2. Environment-specific variables (e.g., in values-prod.yaml)
env:
- name: APP_ENV
value: production
- name: PUBLIC_URL
value: https://api.acme.example
# 3. Additional situational overrides
extraEnv:
- name: LOG_LEVEL
value: info
# 4. Mount entire ConfigMaps or Secrets
envFrom:
- configMapRef:
name: acme-shared-config
- secretRef:
name: acme-api-keys
optional: true
Usage in Sidecar, Init Container, and Jobs
The exact same four fields work identically in chart.sidecar, chart.initContainer, chart.job, and the root job helper:
chart:
enabled: true
fullnameOverride: "acme-backend"
container:
image: registry.acme.corp/backend:2.0.0
sidecar:
enabled: true
image: fluent/fluent-bit:3.1
staticEnv:
- name: SERVICE_NAME
value: acme-backend
env:
- name: LOG_LEVEL
value: warn
extraEnv: []
envFrom:
- configMapRef:
name: fluentbit-env
Combining Multiple Values Files
A typical staging or production command where staticEnv from the base file is preserved while only env or extraEnv is overridden:
# values-prod.yaml (contains only environment-specific overrides)
chart:
container:
env:
- name: APP_ENV
value: production
- name: PUBLIC_URL
value: https://api.acme.example
helm upgrade --install acme-backend . \
--namespace acme-prod \
-f values.yaml \
-f values-prod.yaml