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

Time:04-07

When I run the command

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

I get the error

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

What can be?

CodePudding user response:

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

Your volumes section is placed wrongly. Try:

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

CodePudding user response:

Below is the sample deployment file :

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: 
  • Related