Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The PersistentVolume is invalid: spec: Required value: must specify a volume type

I'm trying to create a Persistent Volume on top of/based off of an existing Storage Class Name. Then I want to attach the PVC to it; so that they are bound. Running the code below, will give me the "sftp-pv-claim" I want, but it is not bound to my PV ("sftp-pv-storage"). It's status is "pending".

The error message I receive is: "The PersistentVolume "sftp-pv-storage" is invalid: spec: Required value: must specify a volume type". If anyone can point me in the right direction as to why I'm getting the error message, it'd be much appreciated.

Specs:

I'm creating the PV and PVC using a helm chart.

I'm using the Rancher UI to see if they are bound or not and if the PV is generated.

The storage I'm using is Ceph with Rook (to allow for dynamic provisioning of PVs).

Error:

The error message I receive is: "The PersistentVolume "sftp-pv-storage" is invalid: spec: Required value: must specify a volume type".

Attempts:

I've tried using claimRef and matchLabels to no avail.

I've added "volumetype: none" to my PV specs.

If I add "hostPath: path: "/mnt/data"" as a spec to the PV, it will show up as an Available PV (with a local node path), but my PVC is not bonded to it. (Also, for deployment purposes I don't want to use hostPath.

## Create Persistent Storage for SFTP
## Ref: https://www.cloudtechnologyexperts.com/kubernetes-persistent-volume-with-rook/

kind: PersistentVolume
apiVersion: v1
metadata:
  name: sftp-pv-storage
  labels:
    type: local
    name: sftp-pv-storage
spec:
  storageClassName: rook-ceph-block
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  allowVolumeExpansion: true
  volumetype: none

---
## Create Claim (links user to PV)
##  ==> If pod is created, need to automatically create PVC for user (without their input)

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: sftp-pv-claim
spec:
  storageClassName: sftp-pv-storage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
like image 713
CodeNewb Avatar asked Oct 03 '19 20:10

CodeNewb


People also ask

How do I create a persistentvolume in IBM® Cloud Private?

You can create a hostPath PersistentVolume by using the management console. To view a list of persistent volumes in your IBM® Cloud Private cluster, from the navigation menu, click Platform > Storage. From the navigation menu, click Platform > Storage. Click Create PersistentVolume.

What is a hostpath persistentvolume?

A hostPath volume mounts a file or directory from the host node's file system into your pod. For more information about hostPath volume, see Types of Volumes . A hostPath PersistentVolume must be used only in a single-node cluster.

How do I add a label to a persistentvolume?

Storage Type - (required) Select Host path. Attach a label to the PersistentVolume. A label is a key and value pair. For example: type=local. This parameter is optional. Parameters for storage. Parameters are supplied as key and value pairs.

Do I need to set the volume type for local volumes?

Note: For most volume types, you do not need to set this field. It is automatically populated for AWS EBS, GCE PD and Azure Disk volume block types. You need to explicitly set this for local volumes.


1 Answers

The PersistentVolume "sftp-pv-storage" is invalid: spec: Requiredvalue: must specify a volume type.

In PV manifest you must provide type of volume. List of all supported types are described here. As you are using Ceph I assume you will use CephFS.

A cephfs volume allows an existing CephFS volume to be mounted into your Pod. Unlike emptyDir, which is erased when a Pod is removed, the contents of a cephfs volume are preserved and the volume is merely unmounted. This means that a CephFS volume can be pre-populated with data, and that data can be “handed off” between Pods. CephFS can be mounted by multiple writers simultaneously.

Example of CephFS you can find in Github.

If I add "hostPath: path: "/mnt/data"" as a spec to the PV, it will show up as an Available PV (with a local node path), but my PVC is not bonded to it.

If you will check Official Kubernetes docs about storageClassName.

A claim can request a particular class by specifying the name of a StorageClass using the attribute storageClassName. Only PVs of the requested class, ones with the same storageClassName as the PVC, can be bound to the PVC.

storageClassName of your PV and PVC are different.

PV:

spec:
  storageClassName: rook-ceph-block

PVC:

spec:
  storageClassName: sftp-pv-storage

Hope it will help.

like image 186
PjoterS Avatar answered Nov 15 '22 11:11

PjoterS