io.k8s.api.core.v1.Container 中的未知字段 "volumes"

unknown field "volumes" in io.k8s.api.core.v1.Container

当我运行命令

kubectl create -f .k8s/deployment.yaml --context=cluster-1

我收到错误

error: error validating ".k8s/deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.containers[0]): unknown field "volumes" in io.k8s.api.core.v1.Container; if you choose to ignore these errors, turn validation off with --validate=false

deployment.yaml

apiVersion: apps/v1
kind: Deployment
  ...
    spec:
      containers:
        ...
        volumes:
        - name: auth
          secret:
            secretName: d-secrets
            items:
            - key: SECRETS
              path: foobar.json

可以是什么?

下面是示例部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: <Image>
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: <Port>
        volumeMounts:
          - mountPath: 
            name: 

...unknown field "volumes" in io.k8s.api.core.v1.Container

您的 volumes 部分放置错误。尝试:

apiVersion: apps/v1
kind: Deployment
spec:
  ...
  template:
    ...
    spec:
      containers:
      - name: ...
        ...
      volumes:  <-- should be same level as `containers`
      - name: auth
        secret:
          secretName: d-secrets
          items:
          - key: SECRETS
            path: foobar.json