Last active
September 13, 2024 19:00
-
-
Save troyharvey/4506472732157221e04c6b15e3b3f094 to your computer and use it in GitHub Desktop.
Using Kubernetes envFrom for environment variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
Never hot
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
Well, if you wish to use
envFrom
, thenwill expose it as if you were doing
export key1=value1 && export key2=value2
.Whereas:
Is equivalent to
export config.yaml=$(cat config.yaml)
(if we ignore that env variables may not have a.
in their name)