The namespace caverns-1c1e0iq is empty. A file with the region sits at ~/market-1c1e0iq/region:
sh
cat ~/market-1c1e0iq/region1. Create the ConfigMap
One command, two sources:
sh
kubectl create configmap market-config -n caverns-1c1e0iq \
--from-literal=MARKET_NAME=monster-market-eu \
--from-file=region=$HOME/market-1c1e0iq/region
kubectl get configmap market-config -n caverns-1c1e0iq -o yamlTwo keys: MARKET_NAME and region.
2. Import every key as environment
sh
kubectl apply -n caverns-1c1e0iq -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: market-web
spec:
replicas: 1
selector:
matchLabels:
app: market-web
template:
metadata:
labels:
app: market-web
spec:
containers:
- name: web
image: stackmonsters/monster-market-web
envFrom:
- configMapRef:
name: market-config
EOFRead it back from inside the container. Replace the Pod name with yours from kubectl get pods:
sh
kubectl get pods -n caverns-1c1e0iq
kubectl exec <pod> -n caverns-1c1e0iq -- printenv MARKET_NAME3. Mount it as files
Apply the Deployment again with a volume:
sh
kubectl apply -n caverns-1c1e0iq -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: market-web
spec:
replicas: 1
selector:
matchLabels:
app: market-web
template:
metadata:
labels:
app: market-web
spec:
containers:
- name: web
image: stackmonsters/monster-market-web
envFrom:
- configMapRef:
name: market-config
volumeMounts:
- name: cfg
mountPath: /etc/market
volumes:
- name: cfg
configMap:
name: market-config
EOF
kubectl exec <new-pod> -n caverns-1c1e0iq -- cat /etc/market/regiontext
ConfigMap key env var file
MARKET_NAME → $MARKET_NAME → /etc/market/MARKET_NAME
region → $region → /etc/market/region