环境:
GCP 容器集群
库比版本:
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"}
在我们的项目中,我们试图大量使用 Configmaps/secrets。
当我们将 configmaps 作为“Voulme 插件”使用时,它是有效的。 但是当它作为 ENV 使用时它不会工作。
root<strong i="14">@localhost</strong> 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
我在我们的应用程序的部署模型中尝试过,它不起作用。 所以我在 kubernetes 站点中举了一个例子并通过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
pod 失败并显示以下消息
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"
文件名作为 configmap 的键。 我做了错误的实施。
@talk2vino那么在 pod 中使用的语法是什么。 我也是这个问题!
最有用的评论
文件名作为 configmap 的键。 我做了错误的实施。