Walk into almost any production Kubernetes cluster and you will find it divided into namespaces: development in one, staging in another, production in a third, and the platform team’s tooling somewhere else entirely. Yet namespaces are also one of the most misunderstood objects in the platform. Newcomers assume they are a security boundary, a performance boundary, or a miniature cluster. They are none of those on their own — but with the right controls, they become the foundation of a well-run multi-team cluster.
This guide explains what a namespace actually is, what it can and cannot do, and how to use it well: the four built-in namespaces, creating and switching namespaces, DNS and cross-namespace traffic, and how ResourceQuota, LimitRange, RBAC and NetworkPolicy turn a simple name scope into genuine isolation. The examples reflect Kubernetes 1.37, the current minor release at the time of writing. If you are still getting comfortable with the basics, start with our Kubernetes tutorial for beginners first, then come back here to go deeper.
What Is a Kubernetes Namespace?
A namespace is a logical scope for names inside a Kubernetes cluster. It groups resources so that two resources with the same name can coexist without colliding, as long as they live in different namespaces. A Deployment called api in development and another called api in production are completely separate objects; Kubernetes treats them as unrelated. That simple idea is the whole point of namespaces: they let many teams, environments and applications share one cluster without constantly stepping on each other’s names.
Every namespaced resource belongs to exactly one namespace. Pods, Services, Deployments, ConfigMaps, Secrets, PersistentVolumeClaims, Roles and RoleBindings are all namespaced, and each must be recreated to move it elsewhere. A few resources are cluster-scoped instead: Nodes, PersistentVolumes, ClusterRoles, ClusterRoleBindings and CustomResourceDefinitions exist outside any namespace. You cannot put a Node into a namespace, and a ClusterRole applies across the whole cluster. Knowing which resources are namespaced saves confusion when you write RBAC rules or list a namespace and wonder why some objects never appear.
Think of a namespace as a folder in a filing cabinet rather than a separate room in a building. The folder keeps documents organised and stops two files with the same name from overwriting each other, but it does not lock the cabinet or reserve a share of the building’s electricity. Namespaces organise. They do not, by themselves, isolate, secure, or allocate resources — which is why this guide spends as much time on ResourceQuota, RBAC and NetworkPolicy as on namespaces themselves. The folder is useful; the locks and the budget are separate mechanisms added on top.
Namespaces also give you a unit for applying policy. A ResourceQuota caps CPU and memory consumption, a LimitRange sets default requests and limits, Roles and RoleBindings control who may do what inside it, and NetworkPolicies control which Pods may talk to each other. Each mechanism is scoped to a namespace, which is why namespaces are the natural boundary for team ownership: a team can be given admin rights inside its namespace without any power over the rest of the cluster. Most clusters organise namespaces by environment (development, staging, production), by team, or by tenant. Pick one pattern and stick to it — a cluster with dev, development and staging-2 is a sign nobody agreed on the scheme first.
What a Namespace Is Not
The most important thing to understand is that a namespace is not a security boundary by itself. Creating a namespace called production does nothing to stop a Pod in development from reaching a Service in production. By default, Kubernetes networking is flat: every Pod can talk to every other Pod and every Service in the cluster, regardless of namespace, unless a NetworkPolicy says otherwise. A namespace does not install a firewall, encrypt traffic, or hide Secrets from anyone with permission to read them. Treat a namespace as a vault and you will be unpleasantly surprised the first time someone looks inside.
A namespace is also not a performance boundary. A runaway workload in one namespace can consume CPU and memory that another namespace’s workloads need, because the scheduler places Pods based on capacity across the whole cluster, not per namespace. Without a ResourceQuota, nothing stops one team’s Deployment from scaling up and starving its neighbours. Without a LimitRange, nothing stops a Pod from running with no limits and consuming whatever it can grab. Resource isolation is built with quotas and limits; the namespace only gives you the scope to attach them.
Nor is a namespace a separate cluster, a virtual machine, or a node pool. Namespaces share the same control plane, the same etcd datastore, and the same Nodes: a control-plane problem affects every namespace equally, and a Node failure takes down Pods from every namespace scheduled on it. This shared fate is what makes namespaces cheap compared with running a cluster per team, but it means they are the wrong tool when you need hard separation. If two workloads must never share a Node or sit under different compliance regimes, use separate clusters or separate node pools with taints and tolerations. Namespaces give you soft multi-tenancy: strong organisation and policy scoping, not hardware-level isolation.
Finally, namespaces cannot be nested. There is no namespace inside a namespace, no hierarchy, and no inheritance of policy from parent to child. Each namespace stands alone. If you want a hierarchy — say, a payments area containing payments-dev and payments-prod — model it with a naming convention, because Kubernetes itself will not do it for you. Some ecosystem projects add hierarchical namespaces on top of Kubernetes, but the core API has no such concept — know that before designing a layout that depends on nesting.
The Four Initial Namespaces
Every cluster starts with four namespaces already in place. See them with one command:
kubectl get namespaces
The output lists default, kube-system, kube-public and kube-node-lease. Each has a distinct job, and understanding them helps you decide what goes where — and what should never go into them.
The default namespace is where resources land when you do not specify one. It is the catch-all, and that is exactly the problem: workloads there are usually there by accident, because someone ran a command without -n or applied a manifest that omitted the namespace field. In a well-run cluster, default stays nearly empty, and anything found there should move into a proper namespace. Some teams forbid deployments into default with admission policy.
The kube-system namespace holds objects created by Kubernetes itself: the control-plane components, CoreDNS, the networking plugin, and other add-ons the cluster needs to function. Do not deploy your applications here, and be careful about changing anything in it — a bad change in kube-system can take down DNS or networking for the whole cluster. Read access for debugging is fine; write access belongs to cluster administrators only.
The kube-public namespace holds resources readable by everyone, including unauthenticated users, such as the cluster-info ConfigMap used during cluster discovery. It is readable cluster-wide by design, so never store anything sensitive there. The kube-node-lease namespace holds the Lease objects each Node renews as a heartbeat so the control plane can detect failed Nodes — pure infrastructure plumbing; leave it alone. One rule covers all four: do not create your own namespaces with the kube- prefix. It is reserved by convention for system namespaces, and using it invites confusion and, in some managed offerings, outright conflicts.
Creating and Switching Namespaces
Creating a namespace takes seconds. The imperative way is a single kubectl command:
kubectl create namespace development
kubectl create namespace staging
kubectl create namespace production
The declarative way, which is what you should use in any serious workflow, is a manifest applied with kubectl:
apiVersion: v1
kind: Namespace
metadata:
name: development
labels:
environment: dev
team: platform
Apply it with kubectl apply -f namespace.yaml. The manifest approach is better for two reasons. First, it is version-controlled: the namespace and its labels live in Git, so anyone can see what was created and why. Second, it lets you attach labels at creation time, and labels make namespaces manageable at scale — select all development namespaces, or all namespaces owned by one team, with a single label selector. In a GitOps workflow, namespaces are just another manifest in the repository.
Namespace names must follow DNS label rules: lowercase letters, numbers and hyphens only, starting and ending with a letter or number, and no more than 63 characters. payments-prod is valid; Payments_Prod is not, and neither is a name with dots or underscores. Kubernetes rejects invalid names at creation time — but know the rule before designing a scheme the API will not accept.
Once a namespace exists, everything you create goes into it if you say so, and into default if you do not. The -n flag selects the namespace for one command:
kubectl get pods -n development
kubectl apply -f deployment.yaml -n staging
kubectl logs -f deployment/api -n production
Typing -n on every command gets old, so you can set a preferred namespace on your current kubeconfig context:
kubectl config set-context --current --namespace=development
After that, plain kubectl get pods lists Pods in development until you change it again. It is convenient, but risky: it is easy to forget which namespace your context points at and apply a manifest to production when you meant staging. Many engineers stay explicit with -n in scripts and CI pipelines, and use a tool such as kubens for interactive switching, because the current-namespace setting is invisible. Make the active namespace visible — a shell prompt showing the current context and namespace is one of the cheapest safety improvements you can make.
Deleting a namespace deletes everything inside it. kubectl delete namespace development removes every Pod, Service, ConfigMap, Secret, Deployment and PersistentVolumeClaim in that namespace, and the operation cannot be undone. It is a powerful way to tear down an ephemeral environment — a namespace per pull request, deleted when the branch merges — but also a one-command disaster against the wrong namespace. Guard production namespaces with RBAC so only a small group can delete them, and consider admission controls that block namespace deletion in production. If a namespace sticks in Terminating, a finalizer on a resource inside it is usually the cause.
DNS and Cross-Namespace Access
Services get DNS names automatically, and namespaces are part of that naming. A Service called api in production is reachable at api.production.svc.cluster.local. Inside the same namespace the short name api is enough, because DNS search domains resolve it locally. From another namespace you need the longer form: api.production usually works, and the full name always works. Cross-namespace calls using only the short name fail confusingly — the name resolves to the wrong Service, or to nothing at all.
That DNS behaviour is also why cross-namespace access is easy by default. A Pod in development can call api.production.svc.cluster.local and reach the production API with no extra configuration, because Kubernetes networking is flat unless a NetworkPolicy restricts it. The namespace boundary does not block the call. This is convenient for shared platform services, and a trap for teams that assumed the boundary was a wall. If a development Pod should never touch production data, you need a NetworkPolicy that says so.
Cross-namespace references have other limits too. An Ingress generally routes only to Services in its own namespace; reaching another namespace’s Service usually requires a Gateway API route. A Pod can mount a ConfigMap or Secret only from its own namespace — there is no cross-namespace mount, so shared configuration must be duplicated or synced by a controller. A PersistentVolumeClaim is namespaced as well, and a Pod can only use a claim from its own namespace.
When you do need deliberate cross-namespace communication, put shared services — an internal registry, a logging collector, a database proxy — in a dedicated namespace such as platform or shared-services, and document the fully qualified DNS names other teams should use. Add NetworkPolicies that explicitly allow the traffic you intend, rather than leaving the default open, and prefer explicit DNS names in configuration over short names whenever caller and Service live in different namespaces, so the dependency is visible in the manifest.
ResourceQuota and LimitRange
ResourceQuota turns a namespace from an organisational label into a resource boundary. A quota sets a hard ceiling on the total resources all objects in a namespace may consume together: CPU and memory requests and limits, plus counts of Pods, Services, ConfigMaps and Secrets. Once the quota is reached, the API server refuses new objects that would exceed it. A Deployment scaling past the quota fails to create its Pods, and the failure is visible immediately — a noisy failure at deploy time beats a silent resource grab that starves the rest of the cluster. For the full list of quotable resources, see the Kubernetes resource quotas documentation.
Here is a quota for a development namespace, capping the team at twenty Pods, ten CPU cores of requests, twenty cores of limits, and thirty-two gigabytes of memory requests:
apiVersion: v1
kind: ResourceQuota
metadata:
name: dev-quota
namespace: development
spec:
hard:
pods: "20"
requests.cpu: "10"
requests.memory: 32Gi
limits.cpu: "20"
limits.memory: 64Gi
services: "10"
persistentvolumeclaims: "5"
Apply it with kubectl apply -f quota.yaml, then check it with kubectl describe quota dev-quota -n development, which shows hard limits alongside current usage. Requests are what the scheduler reserves; limits are the ceiling a container may use. Quote both: quoting only requests lets a container burst far beyond its reservation, while quoting only limits leaves the scheduler with no reservation to plan around. Set the request quota from what the team genuinely needs and the limit quota as a multiple of it — twice the requests is a common starting point — then adjust from real usage data, not guesses.
ResourceQuota alone is not enough, because it only caps the total. A single Pod with no limits could still consume an outsized share of the quota, and a Pod with no requests could be scheduled with no reservation at all. That is what LimitRange is for: it sets defaults and bounds for individual containers, including the default request and limit applied when a Pod specifies none, and the minimum and maximum any container may ask for.
apiVersion: v1
kind: LimitRange
metadata:
name: dev-limits
namespace: development
spec:
limits:
- default:
cpu: 500m
memory: 512Mi
defaultRequest:
cpu: 100m
memory: 128Mi
max:
cpu: "2"
memory: 2Gi
min:
cpu: 50m
memory: 64Mi
type: Container
With this in place, a Pod created without resource fields gets 100 millicores and 128 megabytes of requests, and 500 millicores and 512 megabytes of limits, automatically; a Pod asking for more than two cores is rejected. The combination is the standard pattern: LimitRange keeps individual containers sane, ResourceQuota keeps the namespace total sane. Apply both to every team namespace and the noisy-neighbour problem largely disappears. Quotas also need ongoing attention: a quota that was generous six months ago may be a bottleneck today, and a team that keeps hitting its cap will work around it by splitting workloads across namespaces, which defeats the purpose. Review usage regularly and raise quotas where usage justifies it.
RBAC and NetworkPolicy per Namespace
Role-based access control is where namespaces start to deliver real security. A Role grants permissions inside one namespace only, and a RoleBinding attaches it to a user, group or ServiceAccount in that same namespace. A developer can have full admin rights over development while having no permissions at all in production. That is the normal shape of team ownership in a shared cluster, and the single most valuable thing namespaces enable.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: dev-admin
namespace: development
rules:
- apiGroups: ["apps", ""]
resources: ["deployments", "pods", "services", "configmaps"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: dev-team
namespace: development
subjects:
- kind: Group
name: team-platform
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: dev-admin
apiGroup: rbac.authorization.k8s.io
Two details deserve attention. First, a RoleBinding can only reference a Role in its own namespace; to reuse the same permissions in several namespaces, define the set once as a ClusterRole, then create a RoleBinding in each namespace referencing it. The ClusterRole grants nothing until bound, so this is safe — the binding is still scoped to one namespace. Second, ClusterRoles and ClusterRoleBindings are cluster-scoped and bypass namespace boundaries entirely, so hand them out sparingly and audit them regularly. A ClusterRoleBinding to cluster-admin is full control of the cluster, not just one namespace.
NetworkPolicy is the other half of namespace-level security: it controls traffic, not API access. By default a namespace has no NetworkPolicies, so all traffic is allowed in and out. The most useful policy you can apply is a default-deny, which blocks all ingress and egress and forces every allowed flow to be declared explicitly:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
With that policy in place, nothing can reach the Pods in production and nothing inside can reach out, until you add policies allowing the specific traffic the application needs — ingress from the Ingress controller’s namespace, for example, and egress to the database. One caveat: NetworkPolicies are only enforced if the cluster’s networking plugin supports them. The built-in kubenet provider does not; Calico, Cilium, Weave Net and most managed offerings do. Confirm your plugin enforces NetworkPolicy before relying on it, or your policies will be silently ignored — a check worth doing on day one.
RBAC and NetworkPolicy guard different doors. RBAC controls who can change things through the API; NetworkPolicy controls what running workloads can reach over the network. Tight RBAC without NetworkPolicy still lets any Pod in the cluster talk to a namespace’s Services, and strict NetworkPolicies with loose RBAC still let anyone with API access reconfigure it. You need both, applied per namespace, before you can honestly call a namespace isolated. Combined with quotas, they turn the filing-cabinet folder into a room with a lock and a budget.
Naming Conventions and Best Practices
A namespace scheme is a piece of shared language, and it works best when small, consistent and written down. The most durable pattern is <team>-<environment> or <product>-<environment>: payments-dev, payments-staging, payments-prod. It sorts well, reads well in kubectl output, and makes the environment obvious. Small organisations can use plain environment names — development, staging, production. Avoid abbreviations only one person understands, avoid mixing patterns, and avoid names encoding information that changes, such as a version number.
Labels are the other half of the naming story. Every namespace should carry labels for the environment, the owning team, and ideally a cost centre. Labels let you select, report and automate across namespaces: list every production namespace, find every namespace owned by a team, or feed labels into cost allocation. They cost nothing and save hours later. Put the label scheme in the same document as the naming scheme, and enforce both with admission policy, so a namespace cannot be created without the labels your tooling expects.
There are also times when you should not create a namespace at all. A single small application with a handful of Services does not need three namespaces; one is fine, and splitting it adds DNS complexity for no benefit. A namespace per microservice is almost always a mistake: it multiplies the quotas, policies and bindings to maintain, makes cross-service communication awkward, and turns every deployment into a namespace-management exercise. Namespaces are a unit of ownership and environment, not of code organisation. If two services share a team and a lifecycle, they belong in the same namespace; labels can distinguish them inside it.
Do not create a namespace per pull request or per developer unless you have automation to clean them up. Ephemeral namespaces suit preview environments, but only when creation and deletion are automated and a garbage-collection rule removes the forgotten ones. A cluster littered with stale pr-482 and test-john namespaces is worse than one with too few, because nobody knows what is live and what is abandoned. Keep the total modest and the reasons for each namespace documented: five namespaces everyone understands beat fifty nobody can explain. When someone proposes a new namespace, ask who owns it, what quota it gets, which policies apply, and who cleans it up. If those questions have answers, create it. The best layouts are boring: predictable names, consistent labels, quotas and policies on every team namespace, and nothing in default.
Frequently Asked Questions
Can Kubernetes namespaces be nested?
No. There is no hierarchy or inheritance between namespaces; each stands alone, and a policy applied to one has no effect on any other. Model a hierarchy such as a payments area with a naming convention like payments-dev and payments-prod, because the Kubernetes API provides no parent-child relationship between namespaces.
Is a namespace a security boundary?
Not by itself. A namespace organises resource names and gives you a scope for policy, but it does not block network traffic, hide Secrets, or limit resource use. Real isolation comes from combining namespaces with RBAC for API access, NetworkPolicy for traffic, and ResourceQuota and LimitRange for resource consumption. Without those controls, any Pod can reach any Service in any namespace.
How many namespaces should a cluster have?
There is no fixed number, but usually fewer than you think. Most clusters work well with one namespace per team per environment, plus the four built-in namespaces and one for shared platform services. Start with development, staging and production, and add team namespaces only when a team genuinely needs its own quota and access rules. Avoid a namespace per microservice or per developer unless you have automation to manage them.
How do I delete a namespace and everything in it?
Run kubectl delete namespace followed by the namespace name, and Kubernetes removes every namespaced resource inside it, including Pods, Services, ConfigMaps, Secrets and Deployments. The operation cannot be undone, so restrict who can delete namespaces — especially production ones — with RBAC. A namespace stuck in Terminating usually has a finalizer on a resource inside it.
Do namespaces affect how Services are reached?
Yes. A Service called api in production has the fully qualified DNS name api.production.svc.cluster.local. Inside the same namespace the short name api is enough, but from another namespace you need api.production or the full name. A Pod can only mount a ConfigMap or Secret from its own namespace, and an Ingress generally routes only to Services in its own namespace, so cross-namespace dependencies should use fully qualified names.
Conclusion
Kubernetes namespaces are simple objects with an outsized role in how a cluster is run. They give every resource a scope, let teams share one cluster without name collisions, and provide the unit to which quotas, access control and network policy attach. Used well, they turn a flat list of hundreds of resources into an organised system where ownership is clear and a runaway workload in one corner cannot take down the rest. The key insight is that the namespace itself is only the starting point: the isolation, security and fairness teams expect come from the ResourceQuota, LimitRange, RBAC and NetworkPolicy objects attached to it. To go further, our Kubernetes Deployment YAML tutorial shows how to write the manifests that live inside a namespace, and the CKA certification guide for 2026 covers namespaces as part of the exam syllabus, including the hands-on tasks where they appear most often.
Start small and be deliberate. Agree on a naming scheme, label every namespace, put quotas and a default-deny NetworkPolicy on each team namespace, and keep default empty. Review the layout every few months and delete what is no longer needed. For the full reference, the official Kubernetes namespaces documentation is the authoritative source. A layout built with that discipline stays understandable as the cluster grows — and that is what makes namespaces worth getting right.



