我正在尝试创建一个简单的kubernetes pod并在其中使用kubernetes秘密,但不幸的是我在运行“kubectl create -f pod.yml”后遇到以下错误:
Pod“hello-pod”无效。 spec.containers [0] .env [0] .valueFrom:无效值:“”:一次可能没有指定多个字段
这是我的秘密。:
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
testenv: cWprb3IK
我的pod.yml:
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
labels:
name: hello
spec:
containers:
- name: hello-world
image: myregistry.int/hello-world
ports:
- containerPort: 8095
hostPort: 8095
command: [ "/bin/sh", "-c", "env" ]
env:
- name: testenv
valueFrom:
secretKeyRef:
name: mysecret
key: testenv
首先我创建了秘密,当我输入“kubecetl get secret mysecret -o yaml”时,结果是:
apiVersion: v1
data:
testenv: cWprb3IK
kind: Secret
metadata:
creationTimestamp: 2016-04-08T12:29:19Z
name: mysecret
namespace: default
resourceVersion: "196098"
selfLink: /api/v1/namespaces/default/secrets/mysecret
uid: 846648e7-fd85-11e5-a81b-4439c4383162
type: Opaque
答案 0 :(得分:0)
我尝试在kubernetes的singlePod.yaml文件中定义参数。
apiVersion:v1 亲切:Pod 元数据: name:spring-boot-web-demo 标签: 目的:演示-spring-boot-web 规格: 容器: - 名称:spring-boot-web image:docker.io/joethecoder2/spring-boot-web 环境:["名称":" -Dcassandra_ip","价值":" 127.0.0.1"] 命令:[" java"," -jar"," spring-boot-web-0.0.1-SNAPSHOT.jar"," -D&# 34;," cassandra_ip = 127.0.0.1"," -D"," cassandra_port = 9042"] args:[" -Dcassandra_ip = 127.0.0.1"," -Dcassandra_port = 9042"] restartPolicy:OnFailure
然而,出现错误,错误:错误验证" ./ singlePod.yaml":错误验证数据:字段spec.containers [0] .env [1] .name for v1.EnvVar是需要;如果您选择忽略这些错误,请使用--validate = false来关闭验证。
问题是,我们如何将参数传递给POD.yaml文件,以便传递命令行参数,比如Docker? "%docker run -it -p 8080:8080 joethecoder2 / spring-boot-web -Dcassandra_ip = 127.0.0.1 -Dcassandra_port = 9042"