Skip to content

Kubernetes Namespaces

Kubernetes Namespaces are a mechanism used to partition resources within a single Kubernetes cluster.^[400-devops__06-Kubernetes__basics__README.md, 400-devops__06-Kubernetes__k8s.md] They provide a way to divide cluster resources between multiple users, teams, or projects, allowing for isolation and organization of objects.

Usage

Namespaces are primarily used to organize resources into logical groups. For example, a cms namespace might be created to separate Content Management System resources from other workloads^[400-devops__06-Kubernetes__basics__README.md]. To interact with resources within a specific namespace, commands are typically scoped using the -n or --namespace flag, such as listing pods with kubectl get pods -n <namespace-name>^[400-devops__06-Kubernetes__basics__README.md, 400-devops__06-Kubernetes__k8s.md].

Scoping and Context

While namespaces create virtual clusters within the physical cluster, they do not provide strong security boundaries by themselves. They are useful for preventing naming conflicts between resources (e.g., two teams can both have a Pod named web if they are in different namespaces) and for applying policies to specific groups of resources^[400-devops__06-Kubernetes__k8s.md].

Management

Kubernetes generally comes with default namespaces (such as default), but users can create and manage their own.^[400-devops__06-Kubernetes__k8s.md]

The primary command-line tool for Kubernetes, kubectl, is used to manage namespaces directly^[400-devops__06-Kubernetes__basics__README.md, 400-devops__06-Kubernetes__k8s.md].

Commands

Creation

[kubectl](<./kubectl.md>) create namespace <name>
^[400-devops__06-Kubernetes__basics__README.md]

Listing

[kubectl](<./kubectl.md>) get namespaces
^[400-devops__06-Kubernetes__k8s.md]

Accessing resources in a namespace

[kubectl get pods](<./kubectl-get-pods.md>) -n <namespace-name>
^[400-devops__06-Kubernetes__k8s.md]

Sources

  • 400-devops__06-Kubernetes__basics__README.md
  • 400-devops__06-Kubernetes__k8s.md