- plain test
env:
- name: APP_NAME
value: test-app
- configmap
env:
- name: APP_NAME
valueFrom:
configMapKeyRef: ...
- secrets
env:
- name: APP_NAME
valueFrom:
secretKeyRef: ...
- Here is the command format
kubectl create configmap \
<config-name> --from-literal=<key>=<value>
- Consider the following example
kubectl create configmap \
app-config --from-literal=APP_NAME=test-app
- If you want to take input from the file
kubectl create configmap \
app-config --from-file=<path_to_file>
kubectl create configmap \
app-config --from-file=app_config.properties
my-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-configmap
data:
APP_NAME: test_app
APP_ENV: dev
- Apply the configmap
kubectl apply -f my-configmap.yaml
- To view the configmap
kubectl get configmaps
- Env
envFrom:
- configMapRef:
name: app-config
- Single Env
env:
name: APP_COLOR
valueFrom:
configMapKeyRef:
name: app-config
key: APP_COLOR
- Volume
volumes:
- name: app-config-volume
secret:
secretName: app-config
For example
- Injecting the above
app-configmap
in the pod
apiVersion: v1
kind: Pod
metadata:
name: pod-name
spec:
containers:
- name: container-name
image: ubuntu
envFrom:
- configMapRef:
name: app-configmap
$ kubectl describe pod webapp-color | grep -A 2 -i env
Environment:
APP_COLOR: pink
Mounts:
controlplane $ kubectl describe configmap db-config
Name: db-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
DB_HOST:
----
SQL01.example.com
DB_NAME:
----
SQL01
DB_PORT:
----
3306
Events: <none>
- ConfigName Name: webapp-config-map
- Data: APP_COLOR=darkblue
$ kubectl create configmap webapp-config-map --from-literal=APP_COLOR=darkblue
configmap/webapp-config-map created
- Pod Name: webapp-color
- EnvFrom: webapp-config-map
controlplane $ kubectl get pod webapp-color -o yaml > pod.yaml
controlplane $ kubectl apply -f pod.yaml
pod/webapp-color created
controlplane $ cat pod.yaml | grep -A 3 -i envfrom
envFrom:
- configMapRef:
name: webapp-config-map
name: webapp-color