Kubernetes: ConfigMap won't Work as Consume as ENV

Created on 7 Feb 2017  ·  2Comments  ·  Source: kubernetes/kubernetes

Environment:

GCP Container Cluster

Kube Version:

kubectl version
Client Version: version.Info{Major:"1", Minor:"3", GitVersion:"v1.3.7", GitCommit:"a2cba278cba1f6881bb0a7704d9cac6fca6ed435", GitTreeState:"clean", BuildDate:"2016-09-12T23:15:30Z", GoVersion:"go1.6.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.8", GitCommit:"c5fcb1951afb8150e4574bc234aed957cb586eb0", GitTreeState:"clean", BuildDate:"2017-01-12T02:14:29Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}

In our Project we were trying to use the Configmaps/secrets heavily.

It's works when we consume the configmaps as a "Voulme Plugin". But it won't work when it consume as ENV.

root@localhost env-dir]# cat bcsp-env
discovery_app=discovery
discovery_port=8761

kubectl get configmaps bcsp-var -o yaml
apiVersion: v1
data:
  bcsp-env: |
    discovery_app=discovery
    discovery_port=8761
kind: ConfigMap
metadata:
  creationTimestamp: 2017-02-07T14:33:50Z
  name: bcsp-var
  namespace: default
  resourceVersion: "1689350"
  selfLink: /api/v1/namespaces/default/configmaps/bcsp-var
  uid: 7153f6a7-ed42-11e6-b230-42010af00056

I tried it in our app in deployment model, it wont work. So i take an example in kubernetes site and test via busybox.

cat test.yml
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
    - name: test-container
      image: gcr.io/google_containers/busybox
      command: [ "/bin/sh", "-c", "echo $(DISCOVERY_APP) $(DISCOVERY_PORT)" ]
      env:
        - name: DISCOVERY_APP
          valueFrom:
            configMapKeyRef:
              name: bcsp-var
              key: discovery_app
        - name: DISCOVERY_PORT
          valueFrom:
            configMapKeyRef:
              name: bcsp-var
              key: discovery_port
  restartPolicy: Never

The pod is failed with below messages

kubectl describe pod test-pod
Name:           test-pod
Namespace:      default
Node:           gke-container-cluster-it-default-pool-e1732b12-jn5c/10.242.153.2
Start Time:     Tue, 07 Feb 2017 06:34:51 -0800
Labels:         <none>
Status:         Pending
IP:             10.8.1.21
Controllers:    <none>
Containers:
  test-container:
    Container ID:
    Image:              gcr.io/google_containers/busybox
    Image ID:
    Port:
    Command:
      /bin/sh
      -c
      echo $(DISCOVERY_APP) $(DISCOVERY_PORT)
    Requests:
      cpu:              100m
    State:              Waiting
      Reason:           RunContainerError
    Ready:              False
    Restart Count:      0
    Environment Variables:
      DISCOVERY_APP:    <set to the key 'discovery_app' of config map 'bcsp-var'>
      DISCOVERY_PORT:   <set to the key 'discovery_port' of config map 'bcsp-var'>
Conditions:
  Type          Status
  Initialized   True
  Ready         False
  PodScheduled  True
Volumes:
  default-token-1u3vc:
    Type:       Secret (a volume populated by a Secret)
    SecretName: default-token-1u3vc
QoS Tier:       Burstable
Events:
  FirstSeen     LastSeen        Count   From                                                            SubobjectPath                   Type            Reason          Message
  ---------     --------        -----   ----                                                            -------------                   --------        ------          -------
  26s           26s             1       {default-scheduler }                                                                            Normal          Scheduled       Successfully assigned test-pod to gke-container-cluster-it-default-pool-e1732b12-jn5c
  26s           9s              3       {kubelet gke-container-cluster-it-default-pool-e1732b12-jn5c}   spec.containers{test-container} Normal          Pulling         pulling image "gcr.io/google_containers/busybox"
  25s           8s              3       {kubelet gke-container-cluster-it-default-pool-e1732b12-jn5c}   spec.containers{test-container} Normal          Pulled          Successfully pulled image "gcr.io/google_containers/busybox"
  25s           8s              3       {kubelet gke-container-cluster-it-default-pool-e1732b12-jn5c}                                   Warning         FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "test-container" with RunContainerError: "GenerateRunContainerOptions: Couldn't find key discovery_app in ConfigMap default/bcsp-var"

areconfigmap-api

Most helpful comment

The file name is taken as the key for configmap. I did the wrong implementation.

All 2 comments

The file name is taken as the key for configmap. I did the wrong implementation.

@talk2vino So what is the syntax to use in the pods. I too is having this issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pwittrock picture pwittrock  ·  3Comments

errordeveloper picture errordeveloper  ·  3Comments

chowyu08 picture chowyu08  ·  3Comments

rhohubbuild picture rhohubbuild  ·  3Comments

arun-gupta picture arun-gupta  ·  3Comments