Dharmendra jha
Dharmendra jha

Reputation: 131

getting error while creating kubernetes deployment

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.imagePullSecrets[0]): 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

Upvotes: 0

Views: 6870

Answers (3)

user14115073
user14115073

Reputation: 1

volumeMounts: is a container child.

And volumes: is spec child.

Also volumeMounts and Vloume name should be same.

Upvotes: 0

Faheem
Faheem

Reputation: 3569

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

Upvotes: 3

BogdanL
BogdanL

Reputation: 691

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

Upvotes: 1

Related Questions