Kubernetes基础:ConfigMap:无法找到key的对应方法

文档

其他文档:https://cloudpods.csdn.net/65780df2b8e5f01e1e448d16.html#devmenu2
https://cloudpods.csdn.net/65780753b8e5f01e1e447953.html
https://cloudpods.csdn.net/657808b4b8e5f01e1e447e66.html

创建pod,提示如下错误

[root@host131 config]# kubectl get pods
NAME                 READY   STATUS                       RESTARTS   AGE
configmap-test-pod   0/1     CreateContainerConfigError   0          8s
[root@host131 config]# 

使用kubectl describe命令确认到如下错误信息

[root@host131 config]# kubectl describe pods configmap-test-pod
Name:         configmap-test-pod
Namespace:    default
Priority:     0
Node:         192.168.163.131/192.168.163.131
Start Time:   Fri, 03 Jan 2020 05:18:58 -0500
Labels:       <none>
Annotations:  <none>
Status:       Pending
IP:           10.254.80.4
IPs:
  IP:  10.254.80.4
Containers:
  busybox-container:
    Container ID:  
    Image:         busybox:latest
    Image ID:      
    Port:          <none>
    Host Port:     <none>
    Command:
      sleep
      1000
    State:          Waiting
      Reason:       CreateContainerConfigError
    Ready:          False
    Restart Count:  0
    Environment:
      ENV_VAR_USERNAME:  <set to the key 'user.name' of config map 'user-configmap'>  Optional: false
      ENV_VAR__ID:       <set to the key 'user.id' of config map 'user-configmap'>    Optional: false
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-zdtxx (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-zdtxx:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-zdtxx
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From                      Message
  ----     ------     ----               ----                      -------
  Normal   Scheduled  17s                default-scheduler         Successfully assigned default/configmap-test-pod to 192.168.163.131
  Normal   Pulling    12s (x2 over 16s)  kubelet, 192.168.163.131  Pulling image "busybox:latest"
  Normal   Pulled     10s (x2 over 13s)  kubelet, 192.168.163.131  Successfully pulled image "busybox:latest"
  Warning  Failed     10s (x2 over 13s)  kubelet, 192.168.163.131  Error: couldn't find key user.name in ConfigMap default/user-configmap
[root@host131 config]#

Warning Failed 10s (x2 over 13s) kubelet, 192.168.163.131 Error: couldn’t find key user.name in ConfigMap default/user-

对应方法

使用标准方式的ConfigMap的yml文件,动作执行正常。yml文件如下所示

[root@host131 config]# cat user.yml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: user-configmap
  namespace: default
data:
  user.name: liumiao
  user.id: '1001'
[root@host131 config]#

创建ConfigMap并确认

[root@host131 config]# kubectl create -f user.yml 
configmap/user-configmap created
[root@host131 config]# 
[root@host131 config]# kubectl describe cm user-config
Name:         user-configmap
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
user.id:
----
1001
user.name:
----
liumiao
Events:  <none>

[root@host131 config]# 

创建pod

[root@host131 config]# kubectl create -f busybox-pod.yaml 
pod/configmap-test-pod created
[root@host131 config]# 
[root@host131 config]# kubectl get pods
NAME                 READY   STATUS    RESTARTS   AGE
configmap-test-pod   1/1     Running   0          6s
[root@host131 config]# 

进入pod之中确认引用的环境变量,发现也是正常的

[root@host131 config]# kubectl exec -it configmap-test-pod sh
/ # env |grep ENV
ENV_VAR__ID=1001
ENV_VAR_USERNAME=liumiao
/ #
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值