提问者:小点点

库伯内特斯PVC错误-无法绑定到请求的卷:storageClassName不匹配


我在AWS有一个EKS集群,我在EC2中使用eksctlkubectl进行管理。我正在尝试创建一个持久卷来将其绑定到多个pod。为此,我在区域us-east-1中创建了一个EBS卷(gp2,5GB)。我的清单如下所示;

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: ebsgp2
parameters:
  fsType: ext4
  type: gp2
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
  - key: topology.kubernetes.io/region
    values:
    - us-east-1
  - key: topology.kubernetes.io/zone
    values:
    - us-east-1a
    - us-east-1b
    - us-east-1c
apiVersion: v1
kind: PersistentVolume
metadata:
  name: aws-pv
  labels:
    topology.kubernetes.io/region: us-east-1
    topology.kubernetes.io/zone: us-east-1a
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 5Gi
  persistentVolumeReclaimPolicy: Retain
  volumeMode: Filesystem
  csi:
    driver: ebs.csi.aws.com
    fsType: ext4
    volumeHandle: vol-XXXXXXXXXXXXXXXXX
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ebs-claim
  namespace: namespace1
  labels:
    topology.kubernetes.io/region: us-east-1
    topology.kubernetes.io/zone: us-east-1a
spec:
  volumeName: aws-pv
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: ebsgp2

我使用命令请求了持久卷声明;

kubectl apply -f pvc.yaml

然后我列出PV和PVC下面的命令;

kubectl get pv
kubectl get pvc -n namespace1

PV被创造出来;

NAME     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
aws-pv   5Gi        RWO            Retain           Available                                   27m

我可以看到PVC的状态是悬而未决的;

NAME        STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
ebs-claim   Pending   aws-pv   0                         ebsgp2         20s

kubectl get sc显示在输出下方;

NAME            PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
ebsgp2          kubernetes.io/aws-ebs   Retain          WaitForFirstConsumer   true                   8m53s
gp2 (default)   kubernetes.io/aws-ebs   Delete          WaitForFirstConsumer   false                  3h23m

为了进行调查,我使用命令kubectl描述pvc-n namespace1 ebs-声明描述了PVC,并找到了如下输出;

kubectl describe pvc -n namespace1 ebs-claim
Name:          ebs-claim
Namespace:     namespace1
StorageClass:  ebsgp2
Status:        Pending
Volume:        aws-pv
Labels:        topology.kubernetes.io/region=us-east-1
               topology.kubernetes.io/zone=us-east-1a
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      0
Access Modes:
VolumeMode:    Filesystem
Used By:       <none>
Events:
  Type     Reason          Age                 From                         Message
  ----     ------          ----                ----                         -------
  Warning  VolumeMismatch  30s (x62 over 15m)  persistentvolume-controller  Cannot bind to requested volume "aws-pv": storageClassName does not match

有人能告诉我为什么会这样吗?谢谢你。

参考;

  • https://github.com/kubernetes-sigs/aws-ebs-csi-driver/tree/master/examples/kubernetes/dynamic-provisioning/manifests
  • 库伯内特斯Pod警告:1个节点有卷节点亲和性冲突
  • 库伯内特斯pod失败,卷区不匹配无效

共1个答案

匿名用户

您还需要在'spec'下为'PV'添加'storageClassName'。如果您没有指定'storageClassName',它将使用default,这可能是您遇到此问题的原因,因为PV和PVC'storageClassName'不匹配。

https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reserving-a-persistentvolume

相关问题