Understanding Namespaces Through Analogy
Imagine there are two boys named Mark. To differentiate between them, you refer to them by their last names—Smith and Williams. They come from different houses where people often use first names for those familiar with them. However, when addressing someone from another house or an outsider, the full name is used. In Kubernetes, these “houses” represent namespaces. They allow you to group and manage resources differently based on their context and intended use.
Default Namespace and System Namespaces
By default, when you create objects such as pods, deployments, and services in your cluster, they are placed within a specific namespace (similar to being “inside a house”). The default namespace is automatically created during the Kubernetes cluster setup. Additionally, several system namespaces are created at startup:- kube-system: Contains core system components like network services and DNS, segregated from user operations to prevent accidental changes.
- kube-public: Intended for resources that need to be publicly accessible across users.
If you’re running a small environment or a personal cluster for learning, you might predominantly use the default namespace. In enterprise or production environments, however, namespaces provide essential isolation and resource management by allowing environments like development and production to coexist on the same cluster.

Isolating Resources with Namespaces
Namespaces allow you to set distinct policies and resource limits for different environments. This isolation prevents one namespace from interfering with another. For instance, you can apply separate resource quotas for CPU, memory, and the total number of pods to ensure fair usage across environments.

Managing Namespaces with kubectl
Usingkubectl, you can manage resources across different namespaces. Below are some commonly used commands.
Listing Pods in a Namespace
To list all pods in the default namespace:Creating Pods in Specific Namespaces
When creating a pod without specifying the namespace, it is placed in the default namespace:Without Namespace Specification
With Namespace Specification
Creating a Namespace
You can create a namespace using a YAML file. For example, create a file namednamespace-dev.yml:
Setting the Default Namespace for Your Context
If you’re working across multiple namespaces and want to avoid repeatedly specifying the namespace flag, you can set the default namespace for your current context:Contexts are used to manage multiple clusters and user environments within a single configuration. While switching namespaces is simple, managing contexts is a broader topic that warrants further exploration.
Controlling Resource Usage with ResourceQuotas
To ensure that no single namespace overconsumes cluster resources, Kubernetes allows you to define ResourceQuotas. For example, create a file namedcompute-quota.yaml with the following content: