简体   繁体   English

无法将秘密卷安装到kubernetes

[英]Can't mount a secret volume to kubernetes

My manifest is as follows: 我的清单如下:

  1 apiVersion: v1
  2 kind: Pod
  3 metadata:
  4   name: myapp
  5 spec:
  6   containers:
  7   - name: myapp
  8     image: "myapp"
  9     ports:
 10      - containerPort: 3000
 11     command: ["bash"]
 12     args: ["-c", "sleep 999999"]
 13   imagePullSecrets:
 14     - name: regsecret
 15   volumeMount:
 16     - name: "secret-volume"
 17       mountPath: "/etc/udev"
 18       readOnly: true
 19   volumes:
 20     - name: "secret-volume"
 21       secret:
 22         - name: "myappsecret"

It produces the following error: 它会产生以下错误:

error validating data: [found invalid field volumeMount for v1.PodSpec, field spec.volumes[0].secret: expected object of type map[string]interface{}, but the actual type is []interface {}];

Why is volumeMount invalid? 为什么volumeMount无效? It seems like it is stated here https://kubernetes.io/docs/resources-reference/v1.5/#volume-v1 that there is such directive. 看来这里有https://kubernetes.io/docs/resources-reference/v1.5/#volume-v1这样的指示。

Also I don't really understand how to specify the secret as a mount. 另外,我真的不明白如何将秘密指定为挂载。 Tried several things including a suggestion here: https://github.com/kubernetes/kubernetes/issues/4710 尝试了几件事,包括一个建议: https//github.com/kubernetes/kubernetes/issues/4710

Turns out volumeMount needs to be under the containers directive and slight change to the secret volume structure was necessary: 原来volumeMount需要在容器指令下,并且必须对秘密卷结构稍作改动:

  1 apiVersion: v1
  2 kind: Pod
  3 metadata:
  4   name: myapp
  5 spec:
  6   containers:
  7   - name: myapp
  8     image: "myapp"
  9     ports:
 10      - containerPort: 3000
 11     command: ["bash"]
 12     args: ["-c", "sleep 999999"]
 13     volumeMounts:
 14       - name: "secret-volume"
 15         mountPath: "/etc/secret-volume"
 16         readOnly: true
 17   imagePullSecrets:
 18     - name: regsecret
 19   volumes:
 20     - name: "secret-volume"
 21       secret:
 22         secretName: "myappsecret"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM