What Is a Kubernetes Namespace? Explained Simply for Beginners
Kubernetes namespaces explained from scratch — what they are, why you need them, how resource isolation works, when to use multiple namespaces, and how to work with them using kubectl.
When you first install Kubernetes and run kubectl get pods, the cluster feels like one big space where everything lives together. Then you discover namespaces — and suddenly the cluster gets a lot more organized.
Namespaces are one of those concepts that sounds more complicated than it is. Here is what they actually are and why they matter.
What Is a Namespace?
A namespace is a logical partition inside a Kubernetes cluster. Think of a cluster like an apartment building and namespaces like individual apartments — each apartment is separate, has its own resources, and you cannot accidentally walk into someone else's apartment.
Every resource you create in Kubernetes — Pods, Services, Deployments, ConfigMaps, Secrets — lives inside a namespace. If you do not specify one, Kubernetes puts it in the default namespace.
# List all namespaces in your cluster
kubectl get namespaces
# Typical output on a fresh cluster
NAME STATUS AGE
default Active 10d
kube-node-lease Active 10d
kube-public Active 10d
kube-system Active 10dThe Default Namespaces
default: Where your resources go if you do not specify a namespace. New clusters start with this empty and ready to use.
kube-system: Where Kubernetes itself runs. CoreDNS, the API server, etcd, kube-proxy — all of these live in kube-system. You generally do not touch resources here unless you know exactly what you are doing.
kube-public: A special namespace readable by all users (even unauthenticated ones). Rarely used directly.
kube-node-lease: Contains node lease objects used for heartbeating. Internal Kubernetes mechanism, not something you interact with.
Why Use Multiple Namespaces?
On a personal cluster or for learning, the default namespace is fine. In a real environment with multiple teams, environments, or applications, namespaces serve several important purposes.
Environment Separation
The most common pattern — separate namespaces for different environments running on the same cluster:
kubectl create namespace development
kubectl create namespace staging
kubectl create namespace productionThis keeps prod and dev resources from interfering with each other, and makes it easy to see what is running where:
kubectl get pods -n production
kubectl get pods -n developmentTeam or Application Isolation
Multiple teams sharing a cluster can each own their namespace:
team-platform/
team-backend/
team-data/
team-frontend/
Each team deploys to their namespace, and their resources do not collide with other teams' resources even if they use the same names. Two teams can both have a Service named api in different namespaces without conflict.
Resource Quotas Per Namespace
This is one of the most powerful use cases. You can limit how much CPU, memory, and storage each namespace can consume:
apiVersion: v1
kind: ResourceQuota
metadata:
name: dev-quota
namespace: development
spec:
hard:
requests.cpu: "4"
requests.memory: 8Gi
limits.cpu: "8"
limits.memory: 16Gi
pods: "20"This prevents the development team from accidentally using all cluster resources and starving production.
RBAC by Namespace
You can give different teams different permissions per namespace using Role and RoleBinding (not ClusterRole/ClusterRoleBinding):
# Give a developer read-only access to their team's namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: dev-viewer
namespace: team-backend
subjects:
- kind: User
name: alice@company.com
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: view
apiGroup: rbac.authorization.k8s.ioAlice can now kubectl get pods -n team-backend but cannot see resources in other namespaces or make changes.
Working with Namespaces in kubectl
# Create a namespace
kubectl create namespace my-app
# Run a command in a specific namespace
kubectl get pods -n my-app
kubectl get services -n my-app
kubectl describe deployment api-server -n my-app
# Create a resource in a specific namespace
kubectl apply -f deployment.yaml -n my-app
# List resources across all namespaces
kubectl get pods --all-namespaces
kubectl get pods -A # Same, shorter flag
# Set a default namespace for your kubectl context
kubectl config set-context --current --namespace=my-app
# Now you don't need -n my-app every timeSpecifying namespace in YAML (recommended — makes it explicit):
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: my-app # Explicit namespace in manifest
data:
DB_HOST: "postgres.my-app.svc.cluster.local"What Is and Is Not Namespaced
Most Kubernetes resources are namespaced:
- Pods, Deployments, Services, ConfigMaps, Secrets, PersistentVolumeClaims, Jobs
Some resources are cluster-wide (not namespaced):
- Nodes
- PersistentVolumes
- StorageClasses
- ClusterRoles, ClusterRoleBindings
- Namespaces themselves
# See which resources are namespaced
kubectl api-resources --namespaced=true
kubectl api-resources --namespaced=falseDNS and Namespace Isolation
Services in Kubernetes get DNS names based on their namespace:
<service-name>.<namespace>.svc.cluster.local
For example, a Service named database in namespace production:
database.production.svc.cluster.local
A pod in the production namespace can reach it with just database (short form). A pod in the staging namespace needs the full DNS name database.production.svc.cluster.local — which is a good thing, it makes cross-namespace communication explicit rather than accidental.
Common Patterns
One namespace per environment (small teams):
default → dev work
staging → pre-production
production → live traffic
One namespace per team (larger organizations):
team-platform, team-payments, team-auth, team-reporting
One namespace per service (microservice-heavy orgs):
svc-user-api, svc-payment-api, svc-notification, svc-analytics
Start simple (environment-based) and move to more granular patterns only when you actually need the isolation. Over-fragmenting into too many namespaces creates operational complexity without proportional benefit.
Next steps: read our Kubernetes RBAC explained guide to understand how to control who can access each namespace, and Kubernetes resource limits and requests explained to set up quotas.
Today I Fixed
Short real fixes from production — posted daily
Stay ahead of the curve
Get the latest DevOps, Kubernetes, AWS, and AI/ML guides delivered straight to your inbox. No spam — just practical engineering content.
Related Articles
Build a Kubernetes Cluster with kubeadm from Scratch (2026)
Step-by-step guide to building a real multi-node Kubernetes cluster using kubeadm — no managed services, no shortcuts.
How to Build a DevOps Home Lab for Free in 2026
You don't need expensive hardware to practice DevOps. Here's how to build a complete home lab with Kubernetes, CI/CD, and monitoring using free tools and cloud free tiers.
How to Crack the CKA Exam in 2026: Study Plan, Resources, and Tips
Complete CKA exam prep guide for 2026 — what to study, how to practice, which resources actually help, and tips to pass on the first attempt.