getting error while creating kubernetes deployment

8/15/2020

My deployment is working fine. i just try to use local persistent volume for storing data on local of my application. after that i am getting below error.

error: error validating "xxx-deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.imagePullSecrets0): unknown field "volumeMounts" in io.k8s.api.core.v1.LocalObjectReference; if you choose to ignore these errors, turn validation off with --validate=false

apiVersion: apps/v1
kind: Deployment
metadata:
  name: xxx
  namespace: xxx
spec:
  selector:
    matchLabels:
      app: xxx
  replicas: 3
  template:
    metadata:
      labels:
        app: xxx
    spec:
     containers:
     - name: xxx
       image: xxx:1.xx
       imagePullPolicy: "Always"
       stdin: true
       tty: true
       ports:
       - containerPort: 80
       imagePullPolicy: Always
     imagePullSecrets:
     - name: xxx
       volumeMounts:
        - mountPath: /data
          name: xxx-data
     restartPolicy: Always
     volumes:
      - name: xx-data
        persistentVolumeClaim:
          claimName: xx-xx-pvc
-- Dharmendra jha
kubernetes
kubernetes-deployment

3 Answers

8/16/2020

volumeMounts: is a container child.

And volumes: is spec child.

Also volumeMounts and Vloume name should be same.

-- user14115073
Source: StackOverflow

8/15/2020

You need to move the imagePullSecret further down. It's breaking the container spec. imagePullSecret is defined at the pod spec level while volumeMounts belongs to the container spec

apiVersion: apps/v1
kind: Deployment
metadata:
  name: xxx
  namespace: xxx
spec:
  selector:
    matchLabels:
      app: xxx
  replicas: 3
  template:
    metadata:
      labels:
        app: xxx
    spec:
     containers:
     - name: xxx
       image: xxx:1.xx
       imagePullPolicy: "Always"
       stdin: true
       tty: true
       ports:
       - containerPort: 80
       imagePullPolicy: Always
       volumeMounts:
        - mountPath: /data
          name: xxx-data
     imagePullSecrets:
     - name: xxx
     restartPolicy: Always
     volumes:
      - name: xx-data
        persistentVolumeClaim:
          claimName: xx-xx-pvc
-- Faheem
Source: StackOverflow

8/15/2020

You have an indentation typo in your yaml, volumeMounts is under imagePullSecrets, when it should be at the same level:

     imagePullSecrets:
     - name: xxx
     volumeMounts:
     - mountPath: /data
       name: xxx-data
-- BogdanL
Source: StackOverflow