configmaps not available for a pod?

10/23/2016

I'm repeatedly seeing something like;

Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "some-service" with RunContainerError: "GenerateRunContainerOptions: Couldn't find key app-id in ConfigMap default/intercom"

Where the deployment tries to set env. vars from a configmap, that is:

apiVersion: v1
data:
  intercom: |
    app-id=some-id
    api-key=some-key
kind: ConfigMap
metadata:
  creationTimestamp: 2016-10-23T13:09:58Z
  name: intercom
  namespace: default
  resourceVersion: "3836"
  selfLink: /api/v1/namespaces/default/configmaps/intercom
  uid: ffeea5f0-9921-11e6-b2b7-0acff65e44c3

And the deployment looks like:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: myservice
spec:
  replicas: 2
  template:
    metadata:
     labels:
        run: myservice
    spec:
      containers:
        - name: myservice
          image: somerepo/myservice:v1.0
          env:
            - name: INTERCOM_APPID
              valueFrom:
                configMapKeyRef:
                  name: intercom
                  key: app-id
            - name: INTERCOM_APIKEY
              valueFrom:
                configMapKeyRef:
                  name: intercom
                  key: api-key
          ports:
            - containerPort: 9000
      imagePullSecrets:
        - name: docker-hub-key

What could be wrong here?

-- Ashesh
kubernetes

2 Answers

4/9/2019

You can use config map for environment variables as this
config.yaml

apiVersion: v1 
 kind: ConfigMap 
 metadata:   
   name: config-language 
 data:   
   LANGUAGE: english   
   COUNTRY: spain

deployment.yaml

apiVersion: v1 
kind: Pod 
metadata:   
  name: alipine-temp 
spec:   
  containers:
  - image: alpine
    name: alpine-new
    envFrom:
    - configMapRef:
        name: config-language
    args:
    - /bin/sh
    - -c
    - while true; do echo hello; sleep 10;done
-- shubham_asati
Source: StackOverflow

10/23/2016

Your configmap only contains a single key: intercom

-- Jordan Liggitt
Source: StackOverflow