【发布时间】:2022-05-02 21:10:27
【问题描述】:
我正在使用 GKE 和从 gcloud 组件安装的 kubectl。 我使用 kubectl 创建了一个具有命名空间范围的 pv (gcePersistentDisk)。
apiVersion: v1
kind: PersistentVolume
metadata:
name: cstor-cs-a-disk-david
namespace: ns-david
spec:
gcePersistentDisk:
pdName: cstor-cs-a-disk-david
fsType: ext4
partition: 0
readOnly: false
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
capacity:
storage: 200Gi
这表示使用 create pv 指定命名空间是/是有效的:
http://kubernetes.io/third_party/swagger-ui/#!/api%2Fv1/createNamespacedPersistentVolume
当我运行“kubectl get pv”时,我看到了 pv。
$ kubectl get pv
NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON
cstor-cs-a-disk-david <none> 214748364800 RWO Available
我没想到会这样,因为 pv 不是使用默认命名空间范围创建的。
如果我指定命名空间参数(有效与否),也会发生同样的情况。
$ kubectl get namespaces
NAME LABELS STATUS
default <none> Active
kube-system <none> Active
ns-david <none> Active
$ kubectl get pv --namespace=demo
NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON
cstor-cs-a-disk-david <none> 214748364800 RWO Available
如果我针对此 pv 创建声明并使用“kubectl get pvc”查询它,则找不到声明,但在我指定正确的命名空间时找到。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cstor-cs-a-disk-claim-david
namespace: ns-david
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Gi
volumeName: cstor-cs-a-disk-david
$ kubectl get pvc
NAME LABELS STATUS VOLUME
$ kubectl get pvc --namespace=ns-david
NAME LABELS STATUS VOLUME
cstor-cs-a-disk-claim-david map[] Bound cstor-cs-a-disk-david
pv 有命名空间范围还是全局范围?
【问题讨论】:
标签: kubernetes