ConfigMap Kubernetes YAML: space in value is causing error

10/10/2018

For some strange and unknown reason, when I use a ConfigMap with key value pairs that will be set as environment variables in the pods (using envFrom), my pods fail to start.

Here is the ConfigMap portion of my YAML:

apiVersion: v1
kind: ConfigMap
metadata:
  name: all-config
data:
  # DB configuration
  dbServer: "host.docker.internal"
  dbPort: "3306"

  # problematic config
  validationQuery: 'Select 1'

If I comment out the validationQuery key/value pair, the pod starts. If I leave it in, it fails. If I remove the space, it runs! Very strange behavior as it boils down to a whitespace.

Any ideas on why this fails and how users have been getting around this? Can someone try to reproduce?

-- Chad Van De Hey
kubernetes
yaml

1 Answer

10/10/2018

I honestly believe that it's something with your application not liking environment variables with spaces. I tried this myself and I can see the environment variable with the space nice and dandy when I shell into the pod/container.

PodSpec:

...
spec:
  containers:
  - command:
    - /bin/sleep
    - infinity
    env:
    - name: WHATEVER
      valueFrom:
        configMapKeyRef:
          key: myenv
          name: j
...

$ kubectl get cm j -o=yaml
apiVersion: v1
data:
  myenv: Select 1
kind: ConfigMap
metadata:
  creationTimestamp: 2018-10-10T20:44:02Z
  name: j
  namespace: default
  resourceVersion: "11111111"
  selfLink: /api/v1/namespaces/default/configmaps/j
  uid: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa

root@mypod-xxxxxxxxxx-xxxxx:/# echo $WHATEVER
Select 1
root@mypod-xxxxxxxxxx-xxxxx:/#
-- Rico
Source: StackOverflow