What You Will Learn
Beginner
- What namespaces are and why they matter
- When to use them
- How to create and switch namespaces
A namespace is a logical partition of a Kubernetes cluster. It groups resources and provides isolation between teams or environments.
Terminalbash
# List namespaces
kubectl get namespaces
# Default namespaces:
# default - where your resources go by default
# kube-system - K8s system components
# kube-public - public resources
# kube-node-lease - node heartbeat data
# Create a namespace
kubectl create namespace my-app
# Run a Pod in a specific namespace
kubectl apply -f pod.yaml -n my-app
# Switch default namespace
kubectl config set-context --current --namespace=my-appWhen to use namespaces
Use namespaces for: environments (dev, staging, prod), teams (frontend, backend), or projects. Do NOT use for isolating untrusted tenants - use separate clusters for that.| Use case | Namespace strategy |
|---|---|
| Dev / Staging / Prod | One namespace per environment |
| Multiple teams | One namespace per team |
| Multiple projects | One namespace per project |
| Resource limits | Set quotas per namespace |
Practical Exercise
Run: kubectl get namespaces
Create: kubectl create namespace dev
Apply a Pod to dev: kubectl apply -f pod.yaml -n dev
List pods in dev: kubectl get pods -n dev
Switch: kubectl config set-context --current --namespace=dev
Key Takeaways
- Namespaces partition the cluster logically.
- Default namespaces: default, kube-system, kube-public.
- Use for: environments, teams, projects.
- kubectl apply -n namespace to target a namespace.
- ResourceQuota: limit CPU/memory per namespace.
Comments
Comments
Post a Comment