Saturday, 15 November 2025

kubernets - Namespace

✅ What is a Namespace?

Namespace is a way to divide a Kubernetes cluster into virtual sub-clusters.
Think of it as a folder or workspace inside your cluster where resources (pods, services, deployments, etc.) live.

  • It does not create separate nodes — it’s just logical separation.

  • It helps avoid name conflicts and organize resources.

  • Some namespaces are system-managed, some are user-managed.


[mahesh@devopsvm01 .kube]$ minikube kubectl -- get pods --all-namespaces

NAMESPACE              NAME                                         READY   STATUS    RESTARTS        AGE

default                nginx-web-b9c74675f-2gwnv                    1/1     Running   0               56m

default                nginx-web-b9c74675f-vtvt5                    1/1     Running   0               56m

default                nginx-web-b9c74675f-w8t8l                    1/1     Running   0               31m

kube-system            coredns-66bc5c9577-5t9v7                     1/1     Running   0               7h48m

kube-system            etcd-minikube                                1/1     Running   0               7h48m

kube-system            kube-apiserver-minikube                      1/1     Running   0               7h48m

kube-system            kube-controller-manager-minikube             1/1     Running   0               7h48m

kube-system            kube-proxy-7flzw                             1/1     Running   0               7h48m

kube-system            kube-scheduler-minikube                      1/1     Running   0               7h48m

kube-system            storage-provisioner                          1/1     Running   1 (7h47m ago)   7h48m

kubernetes-dashboard   dashboard-metrics-scraper-77bf4d6c4c-2drbq   1/1     Running   0               6h12m

kubernetes-dashboard   kubernetes-dashboard-855c9754f9-btszn        1/1     Running   0               6h12m

[mahesh@devopsvm01 .kube]$


🔹 Namespaces you are seeing

1️⃣ default

  • All your resources go here if you don’t specify a namespace.

  • Your NGINX deployment is here:

default nginx-web-b9c74675f-2gwnv

2️⃣ kube-system

  • Used by Kubernetes itself to run core components:

    • kube-apiserver

    • kube-controller-manager

    • kube-scheduler

    • kube-proxy

    • coredns

  • You usually don’t touch resources here unless debugging the cluster.

3️⃣ kubernetes-dashboard

  • Used by the Kubernetes Dashboard addon.

  • Runs pods like kubernetes-dashboard and dashboard-metrics-scraper.

  • Keeps dashboard-related resources separate from your workloads.


🔹 Why separate namespaces are useful

  1. Avoid name conflicts

    • You could have a nginx-web deployment in multiple namespaces without clashing.

  2. Organize teams or projects

    • Example:

      • dev namespace → development pods

      • qa namespace → testing pods

      • prod namespace → production pods

  3. Apply resource limits

    • You can set CPU/memory quotas per namespace.

  4. Access control

    • RBAC (Role-Based Access Control) can restrict users to certain namespaces.


🔹 Useful commands

  • List all namespaces:

minikube kubectl -- get ns
  • Create a new namespace:

minikube kubectl -- create namespace dev
  • Create a pod in a specific namespace:

minikube kubectl -- run nginx-test --image=nginx -n dev
  • Get pods in a specific namespace:

minikube kubectl -- get pods -n dev

In short

  • Namespaces = logical partitions of a cluster

  • default = your default workspace

  • kube-system = core Kubernetes components

  • kubernetes-dashboard = dashboard resources

  • Helps with organization, security, and resource management.


For example, You can create a Deployment with the identical name, nginx-web, in multiple different namespaces within the same Kubernetes cluster without any conflict.

🏗️ How to Create the Identical Deployments

The key to creating the identical Deployment names lies in specifying the target Namespace using the --namespace or -n flag with the kubectl command.

1. Create in the production Namespace

First, let's assume you create a new namespace for production, though you can use any name.

Bash
minikube kubectl -- create deployment nginx-web --image=nginx --namespace=production

This command creates a resource addressed as: production/nginx-web

2. Create in the testing Namespace

Next, you can create another Deployment using the exact same name but targeting a different namespace, say testing.

Bash
minikube kubectl -- create deployment nginx-web --image=nginx --namespace=testing

This command creates a resource addressed as: testing/nginx-web

No comments:

Post a Comment

Building a Safer PostgreSQL CI/CD Pipeline with GitHub Actions: Dev → PR Review → Test Promotion

In my previous post, we explored a simple push-to-main deployment strategy . While functional, that model is not considered an industry best...