Namespaces β Organizing Your Cluster
A Namespace is a way to divide cluster resources between multiple users or teams. Think of it as a virtual cluster within your physical cluster.
Namespaces are especially useful when multiple teams share the same cluster or when you want to separate development, staging, and production environments.
Default Namespaces
Kubernetes creates these namespaces by default:
ββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β Namespace β Purpose β
ββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ€
β default β Resources with no namespace go hereβ
β kube-system β System components (DNS, dashboard) β
β kube-public β Publicly readable resources β
β kube-node-lease β Heartbeat data for nodes β
ββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββ
Creating and Using Namespaces
# Create a namespace
kubectl create namespace my-app
# Or define it in YAML
apiVersion: v1
kind: Namespace
metadata:
name: my-app
# Deploy a pod to a specific namespace
kubectl run nginx --image=nginx -n my-app
# List pods in a namespace
kubectl get pods -n my-app
# List all pods across all namespaces
kubectl get pods --all-namespaces
# Set a default namespace for kubectl
kubectl config set-context --current --namespace=my-app
Resource Quotas
Namespaces let you set resource limits per team or environment:
apiVersion: v1
kind: ResourceQuota
metadata:
name: my-quota
namespace: my-app
spec:
hard:
pods: "10"
requests.cpu: "4"
requests.memory: "8Gi"
limits.cpu: "8"
limits.memory: "16Gi"
This prevents a single team from consuming all cluster resources. It is essential for multi-tenant clusters.
When to Use Namespaces
Use namespaces when: multiple teams share a cluster, you need environment separation (dev/staging/prod), or you want to apply different RBAC policies to different groups.
Skip namespaces when: you have a small cluster with a single team, or your cloud provider gives you separate clusters per environment.