Namespaces
4 min read Quiz at the end
Use Namespaces to isolate environments (dev, staging, prod) or teams within one cluster.
Namespaces
# List namespaces
kubectl get namespaces
# Create
kubectl create namespace staging
kubectl apply -f - << EOF
apiVersion: v1
kind: Namespace
metadata:
name: production
labels:
env: prod
EOF
# Work in a namespace
kubectl get pods -n staging
kubectl apply -f deployment.yaml -n staging
# Set default namespace for context
kubectl config set-context --current --namespace=staging
# Delete namespace (deletes all resources inside!)
kubectl delete namespace staging
Topic Quiz · 1 questions
Test your understanding before moving on
1. What happens when you delete a Namespace?
💡 Deleting a namespace cascades and deletes all resources within it.