What is Namespace in Kubernetes: Simple Explanation and Example
namespace in Kubernetes is a way to divide cluster resources between multiple users or projects. It acts like a virtual space inside the cluster, isolating resources such as pods and services so they don't interfere with each other.How It Works
Think of a Kubernetes cluster as a large office building. A namespace is like a separate room or department inside that building. Each room has its own space and resources, so teams can work without bumping into each other.
Namespaces help organize and separate resources like pods, services, and deployments. This separation means you can have multiple projects or teams using the same cluster without mixing their resources. It also helps with managing permissions and resource limits for each group.
Example
This example shows how to create a namespace and run a pod inside it.
kubectl create namespace my-team kubectl run nginx --image=nginx --namespace=my-team kubectl get pods --namespace=my-team
When to Use
Use namespaces when you want to separate environments, teams, or projects within the same Kubernetes cluster. For example, you can have namespaces for development, testing, and production to keep resources isolated.
Namespaces are also useful for applying different access controls and resource limits to different groups. This helps prevent one team from using too many resources or accidentally affecting another team's work.
Key Points
- Namespaces divide cluster resources into virtual groups.
- They isolate resources like pods and services.
- Namespaces help manage access and resource limits.
- They are useful for separating teams, projects, or environments.