我有一个包含 PV 和 PVC 的掌舵图来挂载 NFS 卷,这工作正常。我需要将此 helm 图表安装在具有非常严格和有限的安全措施的新集群上,并且我还看到我的 pod 处于挂起状态,因为它们无法挂载 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
这很奇怪,因为我的掌舵图中的 PVC 根本没有任何 storageClassName: 聚氯乙烯:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gstreamer-claim
namespace: {{ .Release.Namespace }}
spec:
volumeName: gstreamer-{{ .Release.Namespace }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
光伏:
- 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,但无法更改它。
为什么会这样?它是否与群集安全性有关? 如何解决这个问题?
更新
存储类信息:
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。创建具有存储类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
作为默认存储类,无需在 PVC 中指定storageClassName: nfs-client
。