如何让 PVC 是 pending 的状态

如何让 PVC 是 pending 的状态

今天在讨论一个话题,即如何让 PVC 是 pending 的状态,通过讨论,发现道理很简单,如果通过 StorageClass, PVC 和 PV 的 绑定必然是自动的。
若要达成这种效果,手动创建PVC,然后在绑定即可。

1.创建 PVC

$ cat pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc
spec:
  storageClassName: openebs-hostpath
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
kubectl apply -f pvc.yaml

mars@mars-k8s-master1:~$ kubectl get pvc -A
NAMESPACE     NAME                           STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
default       data-my-release-postgresql-0   Bound     pvc-2d917d62-baa7-495d-bafa-218f47786a1f   8Gi        RWO            openebs-hostpath   13d
default       test-pvc                       Pending                                                                        openebs-hostpath   5m50s

2. 创建 pv

mars@mars-k8s-master1:~$ cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv
spec:
  storageClassName: openebs-hostpath
  capacity:
    storage: 3Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
mars@mars-k8s-master1:~$ kubectl apply -f pv.yaml
persistentvolume/test-pv created
$ kubectl get pv
test-pv   3Gi   RWO   Retain   Available      openebs-hostpath   3s

3. edit pvc

$ kubectl edit pvc test-pvc
persistentvolumeclaim/test-pvc edited

$ kubectl edit pvc test-pvc
persistentvolumeclaim/test-pvc edited

$ kubectl get pvc
NAME                           STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
data-my-release-postgresql-0   Bound     pvc-2d917d62-baa7-495d-bafa-218f47786a1f   8Gi        RWO            openebs-hostpath   13d
test-pvc                       Pending   test-pv                                    0                         openebs-hostpath   27m

$ kubectl get pvc
NAME                           STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
data-my-release-postgresql-0   Bound    pvc-2d917d62-baa7-495d-bafa-218f47786a1f   8Gi        RWO            openebs-hostpath   13d
test-pvc                       Bound    test-pv                                    3Gi        RWO            openebs-hostpath   27m

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注