Namespace Management
Intermediate10 min
Create, organize, and manage Kubernetes namespaces with resource quotas and limit ranges for multi-tenant clusters.
Prerequisites
- -kubectl configured
Steps
1
List all namespaces with status
View all namespaces and their current status.
$ kubectl get namespaces -o custom-columns='NAME:.metadata.name,STATUS:.status.phase,AGE:.metadata.creationTimestamp'
2
Create a namespace with labels
Create a new namespace and label it for organization.
$ kubectl create namespace staging && kubectl label namespace staging environment=staging team=platform
3
Set a resource quota on a namespace
Limit the total resources that can be consumed in a namespace.
$ kubectl create quota team-quota --namespace=staging --hard=cpu=4,memory=8Gi,pods=20,services=10
Resource quotas prevent a single team from consuming all cluster resources.
4
View resource usage in a namespace
Check current resource consumption against quotas.
$ kubectl describe quota --namespace=staging
5
Set the default namespace for kubectl
Change the default namespace so you do not need to specify -n on every command.
$ kubectl config set-context --current --namespace=staging
Full Script
FAQ
Discussion
Loading comments...