Namespaces
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.
Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces. Namespaces cannot be nested inside one another and each Kubernetes resource can only be in one namespace.
Namespaces are a way to divide cluster resources between multiple users (via resource quota).
It is not necessary to use multiple namespaces to separate slightly different resources, such as different versions of the same software: use to distinguish resources within the same namespace.
Working with Namespaces
Note: Avoid creating namespaces with the prefix , since it is reserved for Kubernetes system namespaces.
You can list the current namespaces in a cluster using:
Kubernetes starts with four initial namespaces:
kube-system
The namespace for objects created by the Kubernetes system- This namespace is created automatically and is readable by all users (including those not authenticated). This namespace is mostly reserved for cluster usage, in case that some resources should be visible and readable publicly throughout the whole cluster. The public aspect of this namespace is only a convention, not a requirement.
kube-node-lease
This namespace holds objects associated with each node. Node leases allow the kubelet to send heartbeats so that the control plane can detect node failure.
To set the namespace for a current request, use the --namespace
flag.
You can permanently save the namespace for all subsequent kubectl commands in that context.
When you create a , it creates a corresponding DNS entry. This entry is of the form , which means that if a container only uses <service-name>
, it will resolve to the service which is local to a namespace. This is useful for using the same configuration across multiple namespaces such as Development, Staging and Production. If you want to reach across namespaces, you need to use the fully qualified domain name (FQDN).
Not All Objects are in a Namespace
Most Kubernetes resources (e.g. pods, services, replication controllers, and others) are in some namespaces. However namespace resources are not themselves in a namespace. And low-level resources, such as nodes and persistentVolumes, are not in any namespace.
To see which Kubernetes resources are and aren’t in a namespace:
The Kubernetes control plane sets an immutable on all namespaces, provided that the NamespaceDefaultLabelName
feature gate is enabled. The value of the label is the namespace name.
What’s next
- Learn more about creating a new namespace.