Kubernetes 自动将 storageClassName 添加到 PVC

Kubernetes automatically adds the storageClassName to PVC

我有一个包含 PV 和 PVC 的 helm chart 来挂载 NFS 卷,这工作正常。我需要在具有非常严格和有限的安全措施的新集群上安装此 helm chart,我还看到我的 pods 正在挂起,因为它们无法挂载 NFS。

经过一些调查,我发现问题是 PVC 和 PV 具有不同的 storageClassName:

kubectl -n 57 describe pvc gstreamer-claim


Events:
  Type       Reason             Age                 From                         Message
  ----       ------             ----                ----                         -------
  Warning    VolumeMismatch     98s (x83 over 21m)  persistentvolume-controller  Cannot bind to requested volume "gstreamer-57": storageClassName does not match

这很奇怪,因为我的 helm chart 中的 PVC 根本没有任何 storageClassName: 聚氯乙烯:

- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: gstreamer-claim
    namespace: {{ .Release.Namespace }}
  spec:
    volumeName: gstreamer-{{ .Release.Namespace }}
    accessModes:
      - ReadWriteOnce
    resources:
      requests:
        storage: 10Gi

PV:

- apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: gstreamer-{{ .Release.Namespace }}
  spec:
    capacity:
      storage: 10Gi
    accessModes:
      - ReadWriteOnce
    persistentVolumeReclaimPolicy: Recycle
    mountOptions:
      - hard
      - nfsvers=4.1
    nfs:
      server: {{ .Values.global.nfsserver }}
      path: /var/nfs/general/gstreamer-{{ .Release.Namespace }}

我尝试编辑 PVC 但无法更改。

为什么会这样?会不会跟集群安全有关? 如何解决这个问题?

更新

存储class信息:

kubectl -n 57 get sc
NAME                      PROVISIONER                                       AGE
local-storage (default)   kubernetes.io/no-provisioner                      54d
nfs-client                cluster.local/nfs-client-nfs-client-provisioner   43m


kubectl -n 57 get sc local-storage -o yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"},"name":"local-storage"},"provisioner":"kubernetes.io/no-provisioner","volumeBindingMode":"WaitForFirstConsumer"}
    storageclass.kubernetes.io/is-default-class: "true"
  creationTimestamp: "2020-03-31T20:46:39Z"
  name: local-storage
  resourceVersion: "458"
  selfLink: /apis/storage.k8s.io/v1/storageclasses/local-storage
  uid: b8352eb1-7390-11ea-84a7-fa163e393634
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

使用动态配置,您无需显式创建 PV。创建存储 class nfs-client.

的 PVC
apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: gstreamer-claim
    namespace: {{ .Release.Namespace }}
  spec:
    volumeName: gstreamer-{{ .Release.Namespace }}
    accessModes:
      - ReadWriteOnce
    resources:
      requests:
        storage: 10Gi
    storageClassName: nfs-client

另一种选择是将 nfs-client 作为默认存储 class 并且不需要在 PVC 中指定 storageClassName: nfs-client