gpt4 book ai didi

kubernetes - Kubernetes自动将storageClassName添加到PVC

转载 作者:行者123 更新时间:2023-12-02 12:01:11 24 4
gpt4 key购买 nike

我有一个包含PV和PVC的 Helm 图,可以挂载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

这很奇怪,因为我的掌 Helm chart 中的PVC根本没有任何storageClassName:
PVC:

- 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,但无法更改它。

为什么会这样呢?它可以与群集安全性相关吗?
如何解决这个问题?

更新资料

存储类信息:

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

关于kubernetes - Kubernetes自动将storageClassName添加到PVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62004937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com