'Does kubectl delete namespace command deletes associated storageclasses also?
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.
Solution 1:[1]
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:
[email protected]:~$ 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.
Solution 2:[2]
kubectl api-resources --namespaced=false
Above commnd will list all the resources that are not in namespace.
You should see StorageClasses here.

Deleting any namespace will not delete storageclasses.
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 | Community |
| Solution 2 | ns94 |
