Kubernetes Namespaces and Resource Quotas Explained

Namespaces let you divide a single Kubernetes cluster into multiple virtual sub-clusters — useful for separating environments, teams, or projects while sharing the same underlying infrastructure.

What Namespaces Actually Do

Namespaces provide a scope for names (two Deployments named "app" can coexist in different namespaces without conflict) and a boundary for access control and resource limits — but they don't provide network isolation by default.

Default Namespaces

kubectl get namespaces

Every cluster starts with a few built-in namespaces: default (where resources go if unspecified), kube-system (cluster-internal components), and kube-public.

Creating a Namespace

kubectl create namespace staging

Deploying Resources to a Specific Namespace

kubectl apply -f deployment.yaml -n staging

Or specify it directly within the YAML:

metadata:
  name: my-app
  namespace: staging

Common Namespace Organization Patterns

PatternExample
By environmentdevelopment, staging, production
By teamteam-frontend, team-backend
By projectproject-a, project-b

Switching Your Default Namespace Context

kubectl config set-context --current --namespace=staging

Avoids needing -n staging on every command afterward, for the current kubectl context.

Resource Quotas: Limiting What a Namespace Can Consume

apiVersion: v1
kind: ResourceQuota
metadata:
  name: staging-quota
  namespace: staging
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    limits.cpu: "8"
    limits.memory: 16Gi
    pods: "20"
kubectl apply -f resourcequota.yaml

This prevents any single namespace from consuming unbounded cluster resources, important on a shared cluster with multiple teams/projects.

Checking Current Quota Usage

kubectl describe resourcequota staging-quota -n staging

LimitRange: Setting Defaults for Individual Pods

apiVersion: v1
kind: LimitRange
metadata:
  name: staging-limits
  namespace: staging
spec:
  limits:
  - default:
      cpu: 500m
      memory: 256Mi
    defaultRequest:
      cpu: 100m
      memory: 128Mi
    type: Container

Ensures every container gets sensible default resource requests/limits even if not explicitly specified, which also makes Horizontal Pod Autoscaling function correctly (see How to Set Up Horizontal Pod Autoscaling in Kubernetes).

Isolating Network Traffic Between Namespaces (Advanced)

By default, Pods across different namespaces can still communicate freely — genuine network isolation requires NetworkPolicy resources, which depend on your cluster's network plugin (CNI) supporting them.

Deleting a Namespace (Caution)

kubectl delete namespace staging

This deletes every resource within that namespace — Deployments, Services, PVCs, everything — with no confirmation prompt beyond the command itself.

Common Errors

"resourcequota exceeded" when deploying — the namespace's quota is already fully consumed; either free up resources from existing workloads or increase the quota if appropriate.

Continue Reading

Browse more articles in Kubernetes & Container Orchestration.

  • kubernetes namespaces, resource quota kubernetes, kubernetes multi tenancy, limitrange
  • 0 istifadəçi bunu faydalı hesab edir
Bu cavab sizə kömək etdi?

Uyğun məqalələr

What Is Kubernetes and When Do You Need It on a VPS?

Kubernetes is a container orchestration platform — it automates deploying, scaling, and...

How to Install a Single-Node Kubernetes Cluster with k3s

k3s is a lightweight, certified Kubernetes distribution designed to run efficiently on modest...

How to Install kubeadm and Set Up a Multi-Node Kubernetes Cluster

kubeadm is the official tool for bootstrapping a standard, full-featured Kubernetes cluster. This...

Kubernetes Pods, Deployments & Services Explained

Understanding these three core Kubernetes objects — Pods, Deployments, and Services —...

How to Expose Applications with a Kubernetes Ingress Controller (Nginx Ingress)

An Ingress lets you route external HTTP/HTTPS traffic to multiple services within your cluster...