Kubernetes namespaces: concepts & key commands
Source: Dev.to
Introduction
What are Namespaces in Kubernetes?
- A namespace is a logical grouping of resources within a cluster.
- Useful for separating environments such as dev, staging, and prod.
- Helps avoid naming conflicts.
- Enables applying access control and resource quotas.
- Facilitates managing large clusters more effectively.
- Namespaces are logical only; they do not create separate clusters or nodes.
Important Things about Namespaces
- A Kubernetes cluster can contain multiple namespaces.
- Pods run on nodes, not inside namespaces.
- A single node can host Pods from multiple namespaces.
- Namespaces do not provide isolation by default.
- Resources like Pods, Deployments, and Services are namespace‑scoped.
Key namespace commands
List all namespaces
kubectl get namespaces
Lists every namespace present in the cluster.
Get Pods from a specific namespace
kubectl get pods -n
Shows all Pods running in the specified namespace.
Create a namespace
kubectl create ns
Creates a new namespace with the given name.
Create a Pod in the default namespace
kubectl run --image=
Creates a Pod using the specified image in the default namespace.
Create a Pod in a specific namespace
kubectl run --image= -n
Creates a Pod using the specified image in the given namespace.
Delete a Pod from a namespace
kubectl delete pod -n
Removes the specified Pod from the indicated namespace.
Apply a YAML manifest
kubectl apply -f
Creates or updates resources defined in the YAML file (declarative configuration).
Delete a namespace
kubectl delete namespace
Deletes the namespace and all resources it contains. Use with caution.
Key takeaways
- Namespaces provide logical separation but not isolation.
- Use namespaces to organize resources, enforce RBAC, and set resource quotas.
- Common namespace‑scoped resources include Deployments, Services, and Pods.
What’s Next?
- Explore Deployments vs. Pods.
- Understand how controllers manage Pods.
- Study real‑world namespace usage patterns.
I’ll continue documenting my learning as I progress.