DEV Community

Rohan Nalawade
Rohan Nalawade

Posted on

Kubernetes namespaces: concepts & key commands

Introduction
As part of my Kubernetes learning journey, today I focused on understanding Namespaces — what they are, why they exist, and how to work with them using basic kubectl commands.
I have written down my current understanding of namespaces and the commands I practiced hands-on.

What are Namespaces in Kubernetes?

A namespace in Kubernetes is a logical grouping of resources within a cluster.
Namespaces help organize resources and make it easier to:

  • Separate environments (dev, staging, prod)
  • Avoid naming conflicts
  • Apply access control and quotas
  • Manage large clusters more effectively Namespaces are logical, not physical. They do not create separate clusters or nodes.

Important Things about Namespaces

  • A Kubernetes cluster can have multiple namespaces
  • Pods run on nodes, not inside namespaces
  • A single node can run Pods from multiple namespaces
  • Namespaces do not provide isolation by default
  • Resources like Pods, Deployments, and Services are namespace-scoped

Key namespace commands i learned today
Below are the core commands I practiced while learning namespaces.

Get all namespaces in the cluster

kubectl get namespaces
Enter fullscreen mode Exit fullscreen mode

This command lists all namespaces present in the cluster.

Get Pods from a specific namespace

kubectl get pods -n <namespace-name>
Enter fullscreen mode Exit fullscreen mode

Displays all Pods running in the specified namespace.

Create a namespace

kubectl create ns <namespace-name>
Enter fullscreen mode Exit fullscreen mode

Creates a new namespace with the given name.

Create a Pod in the default namespace

kubectl run <pod-name> --image=<image-name>
Enter fullscreen mode Exit fullscreen mode

Creates a Pod using the specified image in the default namespace.

Create a Pod in a specific namespace

kubectl run <pod-name> --image=<image-name> -n <namespace-name>
Enter fullscreen mode Exit fullscreen mode

Creates a Pod using the specified image in the specified namespace.

Delete a Pod from a namespace

kubectl delete pod <pod-name> -n <namespace-name>
Enter fullscreen mode Exit fullscreen mode

Deletes the specified Pod from the given namespace.

Apply a YAML file

kubectl apply -f <file-name.yml>
Enter fullscreen mode Exit fullscreen mode

Creates or updates Kubernetes resources defined in the YAML file. This command is commonly used for declarative configuration.

Delete a namespace

kubectl delete namespace <namespace-name>
Enter fullscreen mode Exit fullscreen mode

Deletes the specified namespace and all resources inside it. This is a destructive operation and should be used carefully.

Key takeaways
Namespaces help organize and manage resources within a Kubernetes cluster, but they do not control where Pods run or provide isolation by themselves.
Understanding namespaces is important before moving on to:

  • Deployments
  • Services
  • RBAC
  • Resource quotas

What’s Next?

  • Next, I plan to explore:
  • Deployments vs Pods
  • How controllers manage Pods
  • Real-world namespace usage patterns

I’ll continue documenting my learning as I go.

Top comments (0)