Kubernetes Namespaces Simplified

Listen to this Post

Check out 60DaysOfDevOps Day 29, where Kubernetes Namespaces are covered in depth here: https://lnkd.in/gb796WvH

6000+ read my free daily LearnXOps newsletter: https://lnkd.in/gpV6-BWT

You Should Know:

1. What Are Kubernetes Namespaces?

Namespaces in Kubernetes provide a way to divide cluster resources among multiple users, teams, or projects. They act as virtual clusters within a single physical cluster.

2. Key Commands for Managing Namespaces

  • List all namespaces:
    kubectl get namespaces
    
  • Create a new namespace:
    kubectl create namespace <namespace-name>
    
  • Switch context to a namespace:
    kubectl config set-context --current --namespace=<namespace-name>
    
  • Delete a namespace:
    kubectl delete namespace <namespace-name>
    

3. Practical Use Cases

  • Isolate Development & Production:
    kubectl create namespace dev
    kubectl create namespace prod
    
  • Resource Quotas per Namespace:
    apiVersion: v1
    kind: ResourceQuota
    metadata:
    name: mem-cpu-quota
    namespace: dev
    spec:
    hard:
    requests.cpu: "2"
    requests.memory: 2Gi
    limits.cpu: "4"
    limits.memory: 4Gi
    

Apply with:

kubectl apply -f quota.yaml

4. Viewing Resources in a Namespace

  • List pods in a specific namespace:
    kubectl get pods -n <namespace-name>
    
  • Describe a resource in a namespace:
    kubectl describe pod <pod-name> -n <namespace-name>
    

5. Advanced Namespace Management

  • Set default namespace permanently:
    kubectl config set-context --current --namespace=<namespace-name>
    
  • Check current namespace:
    kubectl config view --minify --output 'jsonpath={..namespace}'
    

What Undercode Say:

Namespaces are essential for organizing Kubernetes clusters efficiently. They help in:
– Resource isolation (Dev/Test/Prod separation)
– Access control (RBAC per namespace)
– Resource allocation (via quotas)

Pro Tip: Always use namespaces in multi-tenant environments to avoid conflicts.

Bonus Linux Commands for Kubernetes Admins:

 Check cluster nodes 
kubectl get nodes

Check cluster health 
kubectl get componentstatuses

Debug pod issues 
kubectl logs <pod-name> -n <namespace>

Port-forward a service 
kubectl port-forward svc/<service-name> 8080:80 -n <namespace> 

Expected Output:

A well-structured Kubernetes cluster with isolated namespaces, efficient resource quotas, and streamlined access control.

Further Reading:

References:

Reported By: Sandip Das – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image