# Using configMaps from file without mount option

**URL:** <https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673>\
**Category:** General Discussions\
**Created:** [July 13, 2021, 2:20am UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673 "2021-07-13T02:20:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![inbox.amitraj](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/inbox.amitraj/32/7646_2.png) [@inbox.amitraj](https://discuss.kubernetes.io/u/inbox.amitraj)\
**Post date:** [July 13, 2021, 2:20am UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/1 "2021-07-13T02:20:05Z")

</div>

Hi All,

Is it possible to use ConfigMap created using --from-file without mount option in a pod?  
I have created this configmap-

```auto
$ cat amitcm.properties

msg="hello world"

msg1="welcome to this world"

$
$ k create cm amitcm --from-file amitcm.properties 
configmap/amitcm created
$ 
$ k describe cm amitcm
Name: amitcm
Namespace: default
Labels: <none>
Annotations: <none>

Data
====
amitcm.properties:
----
msg="hello world"
msg1="welcome to this world"

Events: <none>
$ 

```

now i would like to use the key/value pair as environment variable in my pod, can this be done without using mount option ?  
I would like to run this pod which writes the values of environment variables in a log file-  
$cat pod.yml

```auto
apiVersion: v1
kind: Pod
metadata:
  labels:
  name: amitpod
spec:
  containers:
  - image: inboxamitraj/amitubuntu
    name: amitpod-c
    envFrom:
    - configMapRef:
        name: amitcm
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo $msg $msg1>>log.txt; sleep 1;done"]

```

### Cluster information:

Kubernetes version: v1.21.0  
Cloud being used:bare-metal  
Installation method: kubeadm  
Host OS: ubuntu  
CNI and version: weave-net 2.8.1  
CRI and version: docker 18

Thank you

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [July 13, 2021, 4:17am UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/2 "2021-07-13T04:17:06Z")

</div>

Yes.

> **[Configure a Pod to Use a ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data)**
>
> ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. This page provides a series of usage examples demonstrating how to create ConfigMaps and configure Pods using data stored in...

---

<div class="post-metadata">

**Author:** ![inbox.amitraj](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/inbox.amitraj/32/7646_2.png) [@inbox.amitraj](https://discuss.kubernetes.io/u/inbox.amitraj)\
**Post date:** [July 15, 2021, 1:37am UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/3 "2021-07-15T01:37:23Z")

</div>

Thank you @protosam  
when we create configmaps from files, the filename becomes the key, now I find it very difficult  
to use it as in environement variable.  
eg. if my filename is cm.properties, the environement variable in my pod would be - cm.properties  
but the problem is - bash does not understand a “.” dot in environement variable.

> <https://unix.stackexchange.com/questions/93532/exporting-a-variable-with-dot-in-it>

I am curious, why it is designed this way?

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [July 15, 2021, 5:09am UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/4 "2021-07-15T05:09:36Z")

</div>

I think it’s because the environment variables are behooven to Bash/Shell programming languages.

---

<div class="post-metadata">

**Author:** ![inbox.amitraj](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/inbox.amitraj/32/7646_2.png) [@inbox.amitraj](https://discuss.kubernetes.io/u/inbox.amitraj)\
**Post date:** [July 15, 2021, 2:16pm UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/5 "2021-07-15T14:16:03Z")

</div>

Thank you !

---

<div class="post-metadata">

**Author:** ![inbox.amitraj](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/inbox.amitraj/32/7646_2.png) [@inbox.amitraj](https://discuss.kubernetes.io/u/inbox.amitraj)\
**Post date:** [July 15, 2021, 3:22pm UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/6 "2021-07-15T15:22:58Z")

</div>

Hi @protosam,  
I managed to figure it out using --from-env-file. if we create configmap this way, the key/value pair inside file are exactly created as Environment variables in the pod.

```auto
kubectl create configmap game-config-env-file \
       --from-env-file=configure-pod-container/configmap/game-env-file.properties

```

here is my setup

```auto
$ cat cm.properties 
msg=hello
msg1=world
$ 

$k create cm amitcm --from-env-file=cm.properties

$ cat pod.yml 
apiVersion: v1
kind: Pod
metadata:
  labels:
  name: amitpod
spec:
  containers:
  - image: inboxamitraj/amitubuntu
    name: amitpod-c
    envFrom:
    - configMapRef:
        name: amitcm
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo $msg $msg1>>log.txt; sleep 1;done"]
$ 
$ k apply -f pod.yml 

$ k exec -it amitpod -- tail -f log.txt
hello world
hello world
hello world
hello world
hello world
hello world

```

Thank you so much for your guidance

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [July 15, 2021, 4:47pm UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/7 "2021-07-15T16:47:05Z")

</div>

Did you see that you can mount configmap data as files as well?

---

<div class="post-metadata">

**Author:** ![inbox.amitraj](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/inbox.amitraj/32/7646_2.png) [@inbox.amitraj](https://discuss.kubernetes.io/u/inbox.amitraj)\
**Post date:** [July 17, 2021, 12:23am UTC](https://discuss.kubernetes.io/t/using-configmaps-from-file-without-mount-option/16673/8 "2021-07-17T00:23:56Z")

</div>

yes, exactly.  
what I found is --from-file option is better if you are passing the values in file directly to your application.  
–from-env-file is better if you would like your pods to use environment variables in its shell.

Thank you
