πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Configuration beginner ⏱ 15 minutes K8s 1.28+

Kubernetes Namespace Best Practices

Organize Kubernetes clusters with namespace best practices. Separation strategies, resource quotas, network policies, RBAC per namespace, naming

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: Use namespaces to separate environments (dev/staging/prod), teams, or applications. Apply ResourceQuotas to prevent resource hogging, NetworkPolicies for network isolation, and RBAC Roles for access control per namespace. Don’t over-namespace β€” most clusters need 5-20 namespaces, not hundreds.

The Problem

  • All resources in default namespace β€” no isolation, hard to manage
  • Teams competing for cluster resources without limits
  • No access control separation between teams/environments
  • Can’t apply different policies to different workloads
  • Naming collisions between applications from different teams

The Solution

Namespace Organization Patterns

Pattern 1: By Environment
β”œβ”€β”€ dev
β”œβ”€β”€ staging
β”œβ”€β”€ production
└── (system namespaces)

Pattern 2: By Team
β”œβ”€β”€ team-frontend
β”œβ”€β”€ team-backend
β”œβ”€β”€ team-data
β”œβ”€β”€ team-ml
└── shared-infra

Pattern 3: By Application (Microservices)
β”œβ”€β”€ app-ecommerce
β”œβ”€β”€ app-payments
β”œβ”€β”€ app-notifications
β”œβ”€β”€ app-analytics
└── platform

Pattern 4: Combined (Recommended)
β”œβ”€β”€ production-frontend
β”œβ”€β”€ production-backend
β”œβ”€β”€ staging
β”œβ”€β”€ dev
β”œβ”€β”€ monitoring
β”œβ”€β”€ logging
β”œβ”€β”€ ingress
└── cert-manager

Create Namespace with Labels

apiVersion: v1
kind: Namespace
metadata:
  name: production
  labels:
    environment: production
    team: platform
    kubernetes.io/metadata.name: production    # Auto-label (K8s 1.22+)
  annotations:
    owner: "platform-team@example.com"
    budget: "engineering"

Resource Quotas

apiVersion: v1
kind: ResourceQuota
metadata:
  name: production-quota
  namespace: production
spec:
  hard:
    requests.cpu: "20"
    requests.memory: "40Gi"
    limits.cpu: "40"
    limits.memory: "80Gi"
    pods: "100"
    services: "20"
    persistentvolumeclaims: "30"
    requests.nvidia.com/gpu: "8"
---
# Limit ranges for individual pods
apiVersion: v1
kind: LimitRange
metadata:
  name: default-limits
  namespace: production
spec:
  limits:
    - default:
        cpu: "500m"
        memory: "512Mi"
      defaultRequest:
        cpu: "100m"
        memory: "128Mi"
      max:
        cpu: "4"
        memory: "8Gi"
      min:
        cpu: "50m"
        memory: "64Mi"
      type: Container

RBAC Per Namespace

# Team can manage their namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: team-admin
  namespace: team-frontend
rules:
  - apiGroups: ["", "apps", "batch"]
    resources: ["*"]
    verbs: ["*"]
  - apiGroups: ["networking.k8s.io"]
    resources: ["ingresses", "networkpolicies"]
    verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: frontend-team-admin
  namespace: team-frontend
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: team-admin
subjects:
  - kind: Group
    name: "frontend-developers"
    apiGroup: rbac.authorization.k8s.io

Namespace vs Cluster: When to Separate

Use Namespaces when:                    Use Separate Clusters when:
β”œβ”€β”€ Same trust level                    β”œβ”€β”€ Different trust levels
β”œβ”€β”€ Shared infrastructure               β”œβ”€β”€ Compliance isolation required
β”œβ”€β”€ Resource quotas sufficient           β”œβ”€β”€ Different K8s versions needed
β”œβ”€β”€ Network policies provide isolation  β”œβ”€β”€ Hard multi-tenancy (untrusted)
β”œβ”€β”€ Same team/org                       β”œβ”€β”€ Different regions/DCs
└── Development vs staging              └── Customer-dedicated environments

Common Issues

Can’t see resources β€” β€œNo resources found in default namespace”

  • Cause: Resources are in another namespace; forgot -n flag
  • Fix: Use kubectl get pods -A (all namespaces); or set default: kubectl config set-context --current --namespace=production

ResourceQuota blocking deployments

  • Cause: Pods don’t set resource requests/limits; quota requires them
  • Fix: Add requests/limits to all pods; or set LimitRange for defaults

Cross-namespace service access

  • Cause: Services are namespace-scoped; need full DNS name
  • Fix: Use <service>.<namespace>.svc.cluster.local for cross-namespace access

Best Practices

  1. Never use default for production β€” create explicit namespaces
  2. Apply ResourceQuotas β€” prevent one team from consuming all resources
  3. Set LimitRange defaults β€” pods without limits get sensible defaults
  4. RBAC per namespace β€” teams can only access their namespaces
  5. NetworkPolicy per namespace β€” default deny + explicit allows
  6. Label namespaces β€” enables namespace-based NetworkPolicy selectors
  7. 5-20 namespaces is typical β€” don’t over-namespace (one per microservice is too many)
  8. Set default namespace in context β€” kubectl config set-context --current --namespace=X

Key Takeaways

  • Namespaces provide logical isolation: resource quotas, RBAC, network policies
  • Not physical isolation β€” pods in different namespaces share nodes and network
  • Label namespaces for NetworkPolicy cross-namespace rules
  • ResourceQuota prevents resource hogging; LimitRange sets per-pod defaults
  • Cross-namespace access: <service>.<namespace>.svc.cluster.local
  • Typical patterns: by environment, by team, or combined
  • Use separate clusters for hard multi-tenancy or compliance requirements
#namespaces #multi-tenancy #resource-quotas #organization #best-practices
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens