Namespace Basics
What are Kubernetes Namespaces?
Kubernetes namespaces are virtual clusters that provide a mechanism for isolating groups of resources within a single cluster. They act as a fundamental organizational unit for managing and segregating Kubernetes resources, enabling better resource management and access control.
Key Characteristics of Namespaces
Namespaces offer several critical features for resource organization:
Characteristic |
Description |
Resource Isolation |
Separate resources into logical groups |
Access Control |
Implement granular permission management |
Resource Naming |
Prevent naming conflicts across different teams |
Cluster Segmentation |
Divide cluster resources for multiple projects |
Namespace Architecture
graph TD
A[Kubernetes Cluster] --> B[Namespace 1]
A --> C[Namespace 2]
A --> D[Namespace 3]
B --> E[Pods]
B --> F[Services]
C --> G[Deployments]
C --> H[ConfigMaps]
Creating and Managing Namespaces
Example of creating a namespace using kubectl:
## Create a new namespace
kubectl create namespace development
## Verify namespace creation
kubectl get namespaces
## Create a resource in a specific namespace
kubectl create deployment nginx-app --image=nginx -n development
Default Namespaces
Kubernetes provides several default namespaces:
default
: Resources without a specified namespace
kube-system
: System-level resources and core Kubernetes components
kube-public
: Publicly accessible resources
kube-node-lease
: Node heartbeat information
Resource Scope in Namespaces
Most Kubernetes resources are namespace-scoped, meaning they exist within a specific namespace. However, some cluster-level resources like nodes and persistent volumes are not namespace-bound.