简体   繁体   中英

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? It seems like it is stated here https://kubernetes.io/docs/resources-reference/v1.5/#volume-v1 that there is such directive.

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

Turns out volumeMount needs to be under the containers directive and slight change to the secret volume structure was necessary:

  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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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