Does kubectl delete namespace command deletes associated storageclasses also?

1/23/2018

I am new to Kubernetes, and have a question about it.

When we create a statefulset, it gets associated with its PVC and the PVC will be associated a storageclass.

So when we execute command "kubectl delete namespace", should it delete the storageclasses also?

P.S. The cluster is running on AWS.

-- AVINASH SHRIMALI
amazon-web-services
google-kubernetes-engine
kubectl
kubernetes

1 Answer

1/23/2018

Not All Objects are in a Namespace

Most Kubernetes resources (e.g. pods, services, replication controllers, and others) are in some namespaces. And low-level resources, such as nodes and persistentVolumes, are not in any namespace. Source.

The storage class is not a namespace object. Try to run $ kubectl get storageclass --all-namespaces and you will notice that there is not even the indication of the namespace:

xxx@xxxxx.xx:~$ kubectl get storageclass --all-namespaces

NAMESPACE   NAME                 PROVISIONER
            slow                 kubernetes.io/gce-pd
            standard (default)   kubernetes.io/gce-pd

Therefore I have never paid attention, but I believe that if you delete a namespace nothing will happen to the Storage class objects.

Update:

I created a namespace class "paolo" the following StorageClass:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: slow
  namespace: paolo
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-standard
  zones: us-central1-a, us-central1-b

I didn't received any error, I deleted the namespace paolo and as expected the StorageClass was still there

My test has been performed on Google Cloud Platform.

-- GalloCedrone
Source: StackOverflow