Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does kubernetes pv recognize namespace when created/queried with kubectl?

Tags:

kubernetes

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?

like image 734
David Martin Avatar asked Aug 31 '15 16:08

David Martin


1 Answers

PVs, like nodes, are not scoped to any namespace. However, as you noted PVCs, are.

like image 78
Sreekanth Pothanis Avatar answered Nov 11 '22 11:11

Sreekanth Pothanis