✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes Namespaces and Organization

Kubernetes Namespaces and Organization help structure and isolate workloads across clusters, enabling efficient resource management and team collaboration.

Kubernetes Namespaces and Organization concerns the mechanisms by which a single physical cluster is partitioned into logically isolated groupings of resources, enabling multiple teams, applications, or environments to share the same underlying infrastructure without their objects, names, or policies colliding. A namespace provides a scope for names and a boundary against which access control and resource governance can be applied, without requiring separate clusters for every distinct workload or tenant.


The Namespace Object

Purpose of Namespaces

A namespace exists to divide a cluster's resources into non-overlapping sets, each with its own naming scope: two Pods named worker can coexist in the cluster as long as they belong to different namespaces. Namespaces are intended for dividing resources among multiple users, teams, or applications within a single cluster, rather than for arbitrary directory-like organization of unrelated objects.

apiVersion: v1
kind: Namespace
metadata:
  name: codartium-team
  labels:
    environment: production

Default Namespaces

Every cluster ships with several built-in namespaces: default, used for objects that do not specify a namespace explicitly; kube-system, containing objects created by the Kubernetes system itself; kube-public, readable by all users including unauthenticated ones, typically for cluster-wide information; and kube-node-lease, holding lease objects used for node heartbeat tracking.


Namespaced vs. Cluster-Scoped Resources

Namespaced Resources

Most workload-related resources, Pods, Deployments, Services, ConfigMaps, Secrets, exist within the scope of a single namespace and are only visible and addressable within it by default.

Cluster-Scoped Resources

Some resources exist independently of any namespace, because they represent infrastructure-wide concepts rather than application-specific configuration: Nodes, PersistentVolumes, StorageClasses, ClusterRoles, and Namespace objects themselves are all cluster-scoped.

kubectl api-resources --namespaced=true
kubectl api-resources --namespaced=false
full identity = ( namespace , kind , name )

Referencing Objects Across Namespaces

Same-Namespace Resolution

Most references within a manifest, such as a Pod referencing a ConfigMap by name, are resolved within the same namespace as the referencing object; a Pod cannot mount a ConfigMap that exists in a different namespace by name alone.

Cross-Namespace Service Access

Services can be reached from other namespaces using their fully qualified DNS name, which includes the namespace as a component, allowing controlled cross-namespace communication without requiring resources to share a namespace.

codartium-api.codartium-team.svc.cluster.local
kubectl exec -it debug-pod -n other-namespace -- curl codartium-api.codartium-team.svc.cluster.local

Governance Through Namespaces

RBAC Scoping

A Role and its associated RoleBinding grant permissions scoped to a single namespace, allowing fine-grained, per-team or per-application access control, in contrast to a ClusterRole and ClusterRoleBinding, which grant permissions across the entire cluster.

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: codartium-team
  name: deployment-manager
rules:
  - apiGroups: ["apps"]
    resources: ["deployments"]
    verbs: ["get", "list", "watch", "update"]

ResourceQuota and LimitRange

ResourceQuota and LimitRange objects are themselves namespaced, meaning resource governance, aggregate CPU and memory ceilings, object count limits, and default sizing, is applied per namespace, allowing different teams or environments sharing a cluster to operate under independently tuned constraints.

Network Policies

NetworkPolicy objects are also namespace-scoped, and commonly use namespace labels as a selection criterion, allowing traffic rules to be expressed in terms of which namespaces are permitted to communicate with which, forming a coarse-grained network segmentation model layered on top of the flat Pod network.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-from-frontend
  namespace: codartium-team
spec:
  podSelector: {}
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              team: frontend

Organizational Patterns

Environment Separation

A common pattern uses namespaces to separate environments, development, staging, production, within a single cluster, though production workloads are frequently isolated into entirely separate clusters for stronger fault and security isolation than namespace boundaries alone provide.

Team or Application Ownership

Namespaces are frequently aligned with team or application ownership boundaries, allowing quotas, RBAC policies, and network segmentation to map directly onto organizational structure, simplifying both governance and cost attribution.

kubectl create namespace codartium-staging
kubectl config set-context --current --namespace=codartium-staging
kubectl get all -n codartium-staging

Limits of Namespace Isolation

Namespace boundaries are a logical, not a security, isolation mechanism by default: Pods in different namespaces still share the same underlying nodes, kernel, and, absent NetworkPolicy restrictions, network reachability. Strong multi-tenant isolation, where mutually distrusting workloads must not affect one another, typically requires namespaces to be combined with NetworkPolicies, resource quotas, Pod security standards, and, in the strongest cases, dedicated node pools or separate clusters.