Skip to content

Instantly share code, notes, and snippets.

@troyharvey
Last active May 9, 2024 10:55
Show Gist options
  • Save troyharvey/4506472732157221e04c6b15e3b3f094 to your computer and use it in GitHub Desktop.
Save troyharvey/4506472732157221e04c6b15e3b3f094 to your computer and use it in GitHub Desktop.
Using Kubernetes envFrom for environment variables
# Use envFrom to load Secrets and ConfigMaps into environment variables
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: mans-not-hot
labels:
app: mans-not-hot
spec:
replicas: 1
selector:
matchLabels:
app: mans-not-hot
template:
metadata:
labels:
app: mans-not-hot
spec:
containers:
- name: app
image: gcr.io/mans-not-hot/app:bed1f9d4
imagePullPolicy: Always
ports:
- containerPort: 80
envFrom:
- configMapRef:
name: env-configmap
- secretRef:
name: env-secrets
# Use config map for not-secret configuration data
apiVersion: v1
kind: ConfigMap
metadata:
name: env-configmap
data:
APP_NAME: Mans Not Hot
APP_ENV: production
# Use secrets for things which are actually secret like API keys, credentials, etc
# Base64 encode the values stored in a Kubernetes Secret: $ pbpaste | base64 | pbcopy
# The --decode flag is convenient: $ pbpaste | base64 --decode
apiVersion: v1
kind: Secret
metadata:
name: env-secrets
type: Opaque
data:
DB_PASSWORD: cDZbUGVXeU5e0ZW
REDIS_PASSWORD: AAZbUGVXeU5e0ZB
@jasonjiang9527
Copy link

thk for ur explain, actually in my case with envFrom.configMapRef , only one env exist and its name is config.yaml , value is .yaml ,i seem to know about how configMapRef works

@tahmmee
Copy link

tahmmee commented May 18, 2022

Never hot

@nice-pink
Copy link

Or for loading explicit values from a secret:

env:
- name: PASSWORD
  valueFrom:
    secretKeyRef:
      name: my-credentials
      key: password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment