Getting an error when trying to create a persistent volume

4/30/2019

I am trying to create a persistent volume on my kubernetes cluster running on an Amazon AWS EC2 instance (Ubuntu 18.04). I'm getting an error from kubectl when trying to create it.

I've tried looking up the error but I'm not getting any satisfactory search results.

Here is the pv.yaml file that I'm using.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv001
  labels:
    type: local
spec:
  capacity:
    storage: 1Gi
    storageClassName: manual
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: /home/ubuntu/data/pv001

Here's the error that I am getting:

Error from server (BadRequest): error when creating "./mysql-pv.yaml": 

PersistentVolume in version "v1" cannot be handled as a 
PersistentVolume: v1.PersistentVolume.Spec: 
v1.PersistentVolumeSpec.PersistentVolumeSource: HostPath: Capacity: 
unmarshalerDecoder: quantities must match the regular expression 
'^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)
#x27;, error found in #10 byte of ...|":"manual"},"hostPat|..., bigger context ...|city": {"storage":"1Gi","storageClassName":"manual"},"hostPath": {"path":"/home/ubuntu/data/pv001"},"p|...

I cannot figure out from the message what the actual error is.

Any help appreciated.

-- redmage123
kubernetes

3 Answers

5/14/2020

Try this:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv001
  labels:
    type: local
spec:
  capacity:
    storage: 1Gi
  storageClassName: manual
 accessModes: ["ReadWriteOnce"]
 persistentVolumeReclaimPolicy: Recycle
 hostPath:
   path: /home/ubuntu/data/pv001

storageClassName is under spec and same level as capacity (You put storageClassName under capacity which is wrong). Read more: https://kubernetes.io/docs/concepts/storage/persistent-volumes/

-- Khoa
Source: StackOverflow

4/30/2019

I don't think it's related to having quotes in the path. It's more about using the right indentation for storageClassName. It should be this instead:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv001
  labels:
    type: local
spec:
  capacity:
    storage: 1Gi
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: /home/ubuntu/data/pv001

You can remove it too, and it will use the default StorageClass

-- Rico
Source: StackOverflow

4/30/2019

remove the storage class from pv definition. storage class is needed for dynamic provisioning of pv's.

in your case, you are using host path volumes. it should work without storage class.

If you are on k8s 1.14 then look at local volumes. refer the below link https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/

-- P Ekambaram
Source: StackOverflow