Filename of configMap shows up as env in the Pod

11/16/2020

I have a file named config.txt, which i used to create configmap myconfig inside minikube cluster.

However, when I use myconfig in a Pod, the name of the file config.txt also shows up as part of the ENV.

How can I correct it?

> cat config.txt
var3=val3
var4=val4

> kubectl create cm myconfig --from-file=config.txt
configmap/myconfig created

> kubectl describe cm myconfig
Name:         myconfig
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
config.txt:
----
var3=val3
var4=val4

Events:  <none>

Pod definition

> cat nginx.yml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx
    envFrom:
      - configMapRef:
          name: myconfig
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

> kubectl create -f nginx.yml
pod/nginx created

Pod EVN inspection, notice the line config.txt=var3=val3 expected it to be just var3=val3

> kubectl exec -it nginx -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=nginx
TERM=xterm
config.txt=var3=val3
var4=val4

KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
NGINX_VERSION=1.19.4
NJS_VERSION=0.4.4
PKG_RELEASE=1~buster
HOME=/root
-- bac-Celd
bash
kubernetes
nginx

1 Answer

11/17/2020

Create configmap like this will do the job:

kubectl create cm myconfig --from-env-file=config.txt
-- Kun Li
Source: StackOverflow