Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigMap won't Work as Consume as ENV #41075

Closed
talk2vino opened this issue Feb 7, 2017 · 6 comments
Closed

ConfigMap won't Work as Consume as ENV #41075

talk2vino opened this issue Feb 7, 2017 · 6 comments

Comments

@talk2vino
Copy link
Contributor

talk2vino commented Feb 7, 2017

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"

@talk2vino
Copy link
Contributor Author

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

@voidtcg
Copy link

voidtcg commented May 9, 2017

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

@qixiaobo
Copy link

But I need to use ,how to?

@bbecker-te
Copy link

Please post the solution. Others would like to know what it was. What does "The file name is taken as the key for configmap. I did the wrong implementation." mean?

@Enough7
Copy link

Enough7 commented Nov 19, 2021

Guys try using kubectl create configmap env-production --from-env-file=.env.production don't use --from-file=

@qixiaobo
Copy link

Yeah
Exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants