Skip to main content
This lesson explains Kubernetes namespaces: what they are, when to use them, and how to manage them with kubectl. Namespaces let you partition cluster resources and apply different policies, quotas, and access controls per logical environment (for example, dev vs prod).

Analogy

Imagine two boys both named Mark. To tell them apart, you use last names: Mark Smith and Mark Williams. They each live in their own household (the Smiths and the Williams). Inside a household, people use only first names (e.g., the Smith father calls his son “Mark”). To refer to the Mark in the other household or from outside, you use the full name. In Kubernetes, each household maps to a namespace. Resources within a namespace can refer to each other by simple names; resources outside the namespace must use the full name (namespace-qualified).

What is a namespace?

Every object you create in this course—Pods, Deployments, Services—lives inside a namespace. If you didn’t specify one, it defaults to the default namespace created automatically when the cluster is provisioned. Kubernetes also creates a few other namespaces by default: For small clusters or experiments you can work in default. In larger or production clusters, namespaces are useful for:
  • Resource isolation (e.g., dev, staging, prod).
  • Applying resource quotas.
  • Assigning different policies and RBAC rules per namespace.
You can assign RBAC, NetworkPolicy, and other policies to a namespace so each namespace enforces its own access and networking rules.
A diagram titled "Namespace – Policies" showing three house-shaped namespaces labeled default, dev, and prod, each containing colorful shape icons. The dev namespace has an attached document icon, implying a policy or configuration applied.

Resource quotas

Namespaces let you limit what workloads inside them can consume. A ResourceQuota applied to a namespace ensures workloads cannot exceed allocated resources (CPU, memory, pod count, etc.), which helps prevent a noisy tenant from starving other namespaces.
An infographic titled "Namespace — Resource Limits" showing stacked colored bands for default, prod, and dev namespaces with icons for containers/pods, storage, CPU and nodes. It visually represents resource allocation limits across Kubernetes namespaces.

DNS and cross-namespace Service access

Within a namespace, resources can address other resources by simple names. For example, a Pod in the default namespace can reach a Service named db-service using only the hostname db-service.
A simple diagram titled "DNS" shows a house-shaped "default" namespace containing three components: a blue circle labeled "web-pod", an orange triangle labeled "db-service", and a purple square labeled "web-deployment".
To reach a Service in a different namespace, use the full DNS name: service.namespace.svc.cluster.local Example connecting from an application:
DNS components:
  • service-name — the Service name
  • namespace — the namespace where the Service lives
  • svc — subdomain used for Services
  • cluster.local — default cluster domain
Kubernetes creates DNS entries for Services automatically when you create the Service.

kubectl and namespaces — common operations

By default, kubectl operates against the current namespace (which defaults to default). Here are common operations and examples.

List Pods in the current namespace

List Pods in a specific namespace

List resources across all namespaces

Common kubectl namespace commands

Tip: Set the namespace on your kubectl context if you work primarily in one namespace. This saves you from repeatedly passing --namespace or -n.
Note about contexts: contexts include cluster and user info. Changing the namespace with kubectl config set-context only affects that context.

Creating resources in a specific namespace

When a manifest omits metadata.namespace, the resource is created in the current namespace. You can override this on the command line or include the namespace in the manifest. Create using the default namespace (current context):
Create in the dev namespace:
Include the namespace in the manifest to make it explicit:

Creating a namespace

Namespace manifest:
Create from manifest:
Or create directly:

ResourceQuota example

To limit resources inside a namespace, apply a ResourceQuota object that sets hard limits for that namespace:
Apply it:
Namespaces are NOT a strong security boundary by themselves. To enforce isolation, combine namespaces with RBAC, NetworkPolicies, and Admission Controllers. Resource quotas only limit consumption within a namespace — they do not prevent misconfigured workloads from impacting cluster stability.

Further reading and references

Practice working with namespaces using your cluster or the available coding exercises.

Watch Video

Practice Lab