关于 kubernetes:配置映射不适用于 pod?

configmaps not available for a pod?

我反复看到类似的东西;

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"

部署尝试设置环境的位置。来自 configmap 的 vars,即:

1
2
3
4
5
6
7
8
9
10
11
12
13
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

部署如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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

这里有什么问题?


你的 configmap 只包含一个键:intercom


您可以将配置映射用于环境变量,因为这样
config.yaml

1
2
3
4
5
6
7
apiVersion: v1
 kind: ConfigMap
 metadata:  
   name: config-language
 data:  
   LANGUAGE: english  
   COUNTRY: spain

部署.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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