'does kubernetes pv recognize namespace when created/queried with kubectl?
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?
Solution 1:[1]
pv and namespaces belong to Cluster, so they are not NameSpaced. pvc is NameSpaced
Solution 2:[2]
Above solution has link to kube docs to see the list. but providing commands here directly (in case to check quickly instead of going through doc)
To see which Kubernetes resources are and aren't in a namespace:
# In a namespace
kubectl api-resources --namespaced=true
# Not in a namespace
kubectl api-resources --namespaced=false
Thank You!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | eastonsuo |
| Solution 2 | Venkatesha K |
