Namespaces

https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/

  • provide a mechanism for isolating groups of resources within a single cluster.
  • Names of resources need to be unique within a namespace, but not across namespaces.
  • Namespace-based scoping is applicable only for namespaced objects (e.g. Deployments, Services, etc.) and not for cluster-wide objects (e.g. StorageClass, Nodes, PersistentVolumes, etc.).

For a production cluster, consider not using the default namespace. Instead, make other namespaces and use those.

Namespaced resources

kubectl api-resources --namespaced=true
NAMESHORTNAMESAPIVERSIONNAMESPACEDKIND
bindingsv1trueBinding
configmapscmv1trueConfigMap
endpointsepv1trueEndpoints
eventsevv1trueEvent
limitrangeslimitsv1trueLimitRange
persistentvolumeclaimspvcv1truePersistentVolumeClaim
podspov1truePod
podtemplatesv1truePodTemplate
replicationcontrollersrcv1trueReplicationController
resourcequotasquotav1trueResourceQuota
secretsv1trueSecret
serviceaccountssav1trueServiceAccount
servicessvcv1trueService
controllerrevisionsapps/v1trueControllerRevision
daemonsetsdsapps/v1trueDaemonSet
deploymentsdeployapps/v1trueDeployment
replicasetsrsapps/v1trueReplicaSet
statefulsetsstsapps/v1trueStatefulSet
localsubjectaccessreviewsauthorization.k8s.io/v1trueLocalSubjectAccessReview
horizontalpodautoscalershpaautoscaling/v2trueHorizontalPodAutoscaler
cronjobscjbatch/v1trueCronJob
jobsbatch/v1trueJob
leasescoordination.k8s.io/v1trueLease
endpointslicesdiscovery.k8s.io/v1trueEndpointSlice
eventsevevents.k8s.io/v1trueEvent
ingressesingnetworking.k8s.io/v1trueIngress
networkpoliciesnetpolnetworking.k8s.io/v1trueNetworkPolicy
poddisruptionbudgetspdbpolicy/v1truePodDisruptionBudget
rolebindingsrbac.authorization.k8s.io/v1trueRoleBinding
rolesrbac.authorization.k8s.io/v1trueRole
csistoragecapacitiesstorage.k8s.io/v1trueCSIStorageCapacity

Non Namespaced resources

kubectl api-resources --namespaced=false
NAMESHORTNAMESAPIVERSIONNAMESPACEDKIND
componentstatusescsv1falseComponentStatus
namespacesnsv1falseNamespace
nodesnov1falseNode
persistentvolumespvv1falsePersistentVolume
mutatingwebhookconfigurationsadmissionregistration.k8s.io/v1falseMutatingWebhookConfiguration
validatingadmissionpoliciesadmissionregistration.k8s.io/v1falseValidatingAdmissionPolicy
validatingadmissionpolicybindingsadmissionregistration.k8s.io/v1falseValidatingAdmissionPolicyBinding
validatingwebhookconfigurationsadmissionregistration.k8s.io/v1falseValidatingWebhookConfiguration
customresourcedefinitionscrd,crdsapiextensions.k8s.io/v1falseCustomResourceDefinition
apiservicesapiregistration.k8s.io/v1falseAPIService
selfsubjectreviewsauthentication.k8s.io/v1falseSelfSubjectReview
tokenreviewsauthentication.k8s.io/v1falseTokenReview
selfsubjectaccessreviewsauthorization.k8s.io/v1falseSelfSubjectAccessReview
selfsubjectrulesreviewsauthorization.k8s.io/v1falseSelfSubjectRulesReview
subjectaccessreviewsauthorization.k8s.io/v1falseSubjectAccessReview
certificatesigningrequestscsrcertificates.k8s.io/v1falseCertificateSigningRequest
flowschemasflowcontrol.apiserver.k8s.io/v1falseFlowSchema
prioritylevelconfigurationsflowcontrol.apiserver.k8s.io/v1falsePriorityLevelConfiguration
ingressclassesnetworking.k8s.io/v1falseIngressClass
runtimeclassesnode.k8s.io/v1falseRuntimeClass
clusterrolebindingsrbac.authorization.k8s.io/v1falseClusterRoleBinding
clusterrolesrbac.authorization.k8s.io/v1falseClusterRole
priorityclassespcscheduling.k8s.io/v1falsePriorityClass
csidriversstorage.k8s.io/v1falseCSIDriver
csinodesstorage.k8s.io/v1falseCSINode
storageclassesscstorage.k8s.io/v1falseStorageClass
volumeattachmentsstorage.k8s.io/v1falseVolumeAttachment

Gotchas

  • Namespaces are intended for use in environments with many users spread across multiple teams, or projects. For clusters with a few to tens of users, you should not need to create or think about namespaces at all. Start using namespaces when you need the features they provide.
  • It is not necessary to use multiple namespaces to separate slightly different resources, such as different versions of the same software: use labels to distinguish resources within the same namespace.
  • Avoid creating namespaces with the prefix kube-, since it is reserved for Kubernetes system namespaces.