09/11/2020 - KUBERNETES
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.
apiVersion: v1
kind: ConfigMap
metadata:
name: address-finder-config
data:
VERSION: ""
HTTP_ADDRESS: :8888
LOG_LEVEL: info
# version: ""
# http_address: :8888
# log_level: info
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