use configmap to make a flexible deployment
create configmap value
To create a configmap for this literal type kubectl create configmap logger --from-literal=log_level=debug
To see all configmaps, kubectl get configmaps
To read the value in the logger configmap, kubectl get configmap/logger -o yaml
To edit the value, kubectl edit configmap/logger
deploy with hardcode
reader-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: logreader
spec:
replicas: 1
template:
metadata:
labels:
name: logreader
spec:
containers:
- name: logreader
image: karthequian/reader:latest
env:
- name: log_level
value: "error"
localhost:~ xunyang$ kubectl create -f reader-deployment.yaml
deployment.extensions "logreader" created
localhost:~ xunyang$ kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
logreader 1 1 1 1 9m
deploy with configmap
reader-configmap-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: logreader-dynamic
spec:
replicas: 1
template:
metadata:
labels:
name: logreader-dynamic
spec:
containers:
- name: logreader
image: karthequian/reader:latest
env:
- name: log_level
valueFrom:
configMapKeyRef:
name: logger #Read from a configmap called log-level
key: log_level #Read the key called log_level