Skip to content
Kubernetes

Namespaces

Partition a cluster into isolated virtual clusters.

By EZ4Code Team
namespaceisolationquota

Code

# Create and switch namespaces
kubectl create namespace staging
kubectl config set-context --current --namespace=staging

# List and inspect
kubectl get namespaces
kubectl get pods -A                # all namespaces
kubectl get pods -n staging

# Resource quota in a namespace
apiVersion: v1
kind: ResourceQuota
metadata:
  name: staging-quota
  namespace: staging
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    pods: "20"

# Delete a namespace (removes everything inside)
kubectl delete namespace staging

Explanation

Namespaces provide a scope for names and a way to divide cluster resources between teams or environments. ResourceQuotas limit how much CPU, memory, and object count a namespace can consume. Switching the default namespace with set-context avoids passing -n on every command.

More Kubernetes Snippets