<aside>
⚠️ The data stored in the ConfigMap, when the container (pod) is created, is used to set the environment variables. If the ConfigMap gets updated later, the pod will continue to use the old values. We need to re-create the pods by performing a rollout (k rollout restart deployment <deployment-name>
) on the deployment to make the new pods use the new data.
</aside>
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
USERNAME: arkalim
PASSWORD: 12345
Using file as a ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: rho-pacs-config
namespace: 16bit
data:
orthanc.json: |
{
/**
* General configuration of Orthanc
**/
}
Passing the entire ConfigMap of key-value pairs to ENV
apiVersion: v1
kind: Pod
metadata:
labels:
name: app
spec:
containers:
- name: nginx
image: nginx
envFrom:
- configMapRef:
name: app-config
Passing a single key-value pair from the ConfigMap to ENV
apiVersion: v1
kind: Pod
metadata:
labels:
name: app
spec:
containers:
- name: nginx
image: nginx
env:
- name: USERNAME
valueFrom:
configMapKeyRef:
name: app-config
key: USERNAME
Passing a config file as ConfigMap (eg. nginx.conf
) by mounting the ConfigMap as a volume
apiVersion: v1
kind: Pod
metadata:
labels:
name: app
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx/conf.d/
volumes:
- name: nginx-config-volume
configMap:
name: nginx-config