Kubectl create for persistent storage erroring out
Asked Answered
P

1

5

I'm trying to deploy a persistent storage for couch DB and it is failing out with the error


kubectl create -f couch_persistant_deploy.yaml

error: error validating "couch_persistant_deploy.yaml": error validating data: couldn't find type: v1.Deployment; if you choose to ignore these errors, turn validation off with --validate=false

###PersistentVolume YAML

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /mnt/sda1/data/test

###PersistentVolumeClaim YAML

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
  labels:
    app: couchdb
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

###Deployment YAML

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: couchdb
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: couchdb
    spec:
      containers:
        - name: couchdb
          image: "couchdb"
          imagePullPolicy: Always
          env:
          - name: COUCHDB_USER
            value: admin
          - name: COUCHDB_PASSWORD
            value: password
          ports:
          - name: couchdb
            containerPort: 5984
          - name: epmd
            containerPort: 4369
            containerPort: 9100
          volumeMounts:
          - mountPath: "/opt/couchdb/data"
            name: task-pv-storage
      imagePullSecrets:
      - name: registrypullsecret2
      volumes:
      - name: task-pv-storage
        persistentVolumeClaim:
        claimName: task-pv-claim

Any leads are really appreciated.

Polyurethane answered 31/1, 2018 at 14:50 Comment(1)
Hi, can you tell which kubernetes version are you using? by using following command you can get the version kubectl version As of v1.9 you need to use apps/v1beta1Header
V
16

Your error message should be like this:

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

See, error message is specific: unknown field "claimName" in io.k8s.api.core.v1.Volume

In your Deployment you need to nest claimName value one level deep inside of its persistentVolumeClaim key, because non-list values must be indented inside their keys (only keys starting a list such as name here - which begins with a dash - don't have to be indented):

  volumes:
  - name: task-pv-storage
    persistentVolumeClaim:
      claimName: task-pv-claim  # fix is here

But you did

  volumes:
  - name: task-pv-storage
    persistentVolumeClaim:
    claimName: task-pv-claim  # invalid

Which makes your Deployment object invalid

Vocation answered 31/1, 2018 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.