I am using GKE with kubectl installed from gcloud components. I have created a pv (gcePersistentDisk) with namespace scope using kubectl.
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
This says that specifying namespace with create pv is/was valid:
http://kubernetes.io/third_party/swagger-ui/#!/api%2Fv1/createNamespacedPersistentVolume
When I run 'kubectl get pv' I see the pv.
$ kubectl get pv
NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON
cstor-cs-a-disk-david <none> 214748364800 RWO Available
I did not expect this because the pv wasn't created with the default namespace scope.
The same happens if I specify a namespace argument (valid or not).
$ 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
If I create a claim against this pv and query it with 'kubectl get pvc' then the claim is not found but is found when I specify the correct namespace.
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
Do pv have namespace scope or are they global?
PVs, like nodes, are not scoped to any namespace. However, as you noted PVCs, are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With