I created configmap this way.
kubectl create configmap some-config --from-literal=key4=value1
After that i created pod which looks like this
I connect to this pod this way
k exec -it nginx-configmap -- /bin/sh
I found the folder /some/path
but i could get value from key4.
If you refer to your ConfigMap
in your Pod
this way:
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: "/var/www/html"
name: config-volume
volumes:
- name: config-volume
configMap:
name: some-config
it will be available in your Pod
as a file /var/www/html/key4
with the content of value1
.
If you rather want it to be available as an environment variable you need to refer to it this way:
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: myfrontend
image: nginx
envFrom:
- configMapRef:
name: some-config
As you can see you don't need for it any volumes and volume mounts.
Once you connect to such Pod
by running:
kubectl exec -ti mypod -- /bin/bash
You will see that your environment variable is defined:
root@mypod:/# echo $key4
value1