You’ve stumbled upon my secret hiding spot! Or just the place I go to look up things I sometimes forget, but hey, thanks for stopping by anyway.
ConfigMap: Creation
IMPERATIVE LITERALS
$ kubectl create configmap appconfigmap \
--from-literal=name=mclane \
--from-literal=catchphrase=yippeekiyay
IMPERATIVE FROM FILE
NOTE: Remember, when using a file that the key will be the name of the file used. In this case, config.txt is the key and will contain the entire contents of the db-info file.
$ kubectl create configmap appconfigmap --from-file config.txt
DECLARATIVE MULTIPLE ENTRIES
apiVersion: v1
data:
config.txt: |
name=gruber
home: nakatomi
kind: ConfigMap
metadata:
name: appconfigmap
DECLARATIVE SINGLE ENTRIES
apiVersion: v1
data:
catchphrase: yippeekiyay
name: mclane
kind: ConfigMap
metadata:
name: appconfigmap
Mount a ConfigMap in a Pod
As a Volume
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginxsec
name: nginxsec
spec:
containers:
- image: nginx
name: nginxsec
volumeMounts:
- name: configmap
mountPath: /tmp
volumes:
- name: configmap
configMap:
Name: appconfigmap
ConfigMaps as Environment Variables [Individual]
apiVersion: v1
kind: Pod
metadata:
labels:
name: nginxenv
spec:
containers:
- image: nginx
name: nginx
env:
- name: DB_USER
valueFrom:
configMapKeyRef:
name: appConfigMap
key: name
ConfigMaps as Environment Variables [–from-env-file]
apiVersion: v1
kind: Pod
metadata:
labels:
name: nginxenv
spec:
containers:
- image: nginx
name: nginx
envFrom:
- configMapRef:
name: appConfigMap