无法在k8s上创建本地持久卷

时间:2020-09-07 00:05:06

标签: kubernetes

在创建本地持久卷时,在k8s上出现PersistentVolume in version "v1" cannot be handled as a PersistentVolume错误。

输出为:

Error from server (BadRequest): error when creating "setLocalPv.yaml": 
PersistentVolume in version "v1" cannot be handled as a PersistentVolume: 
v1.PersistentVolume.Spec: v1.PersistentVolumeSpec.PersistentVolumeSource: 
Local: Capacity: unmarshalerDecoder: quantities must match the regular 
expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$', error found in #10 byte of 
...|ilesystem"},"local":|..., bigger context ...|acity":
{"storage":"10Gi","volumeMode":"Filesystem"},"local":{"path":"/k8sNodeData"},"nodeAffinity":
{|...

我的Yaml文件在这里。

setStorageClassSSD.yaml:

---

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-ssd-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---

setLocalPv.yaml:

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: dataStorage
spec:
  capacity:
    storage: 10Gi
    volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-ssd-storage
  local:
    path: /k8sNodeData
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: disktype
          operator: In
          values:
          - ssd
---

我想知道在哪里修复它。

1 个答案:

答案 0 :(得分:3)

看起来像格式问题。您可以将volumeMode: Filesystem移到capacity级别吗?

  spec:
    capacity:
      storage: 10Gi
    volumeMode: Filesystem
    accessModes:
    - ReadWriteOnce