Day 33 : Working with Namespaces and Services in Kubernetes

Rahul SinghRahul Singh
2 min read

What are Namespaces and Services in k8s?

A Namespace is a logical partition within a Kubernetes cluster to isolate and organize resources like Pods, Services, and Deployments. Each Namespace is like a separate cluster within the same physical cluster.

Why Use Namespaces?

  • 🧩 Isolation: Separate environments (dev, staging, prod) in one cluster

  • πŸ‘₯ Multi-team support: Different teams or apps don’t interfere with each other

  • πŸ” RBAC: Apply access control to specific namespaces

  • πŸ“Š Resource quotas: Limit CPU/memory per namespace

What are Services in Kubernetes?

A Service is an abstraction that defines a stable network endpoint for accessing Pods. It ensures communication between components, even when Pods are dynamically created or deleted.

Why Use Services?

  • πŸ”„ Pods have dynamic IPs β€” Services provide a stable IP and DNS name

  • βš–οΈ Load Balancing between multiple Pods (via selector)

  • πŸ”’ Service Discovery inside the cluster

Today's task:

Task 1:

  • Create a Namespace for your Deployment

  • Use the command kubectl create namespace <namespace-name> to create a Namespace

  • Update the deployment file to include the Namespace

  • Apply the updated deployment using the command: kubectl apply -f deployment.yml -n <namespace-name>

  • Verify that the Namespace has been created by checking the status of the Namespaces in your cluster.

Task 2:

  • Read about Services, Load Balancing, and Networking in Kubernetes.
  1. Service

    • A Service provides a stable network identity (Cluster IP, DNS) to a group of Pods.

    • It load balances traffic across matching Pods using label selectors.

    • Essential for communication between Pods and external access.

  2. Networking

    • Each Pod gets its own IP address.

    • All Pods can communicate with each other across Nodes (flat network).

    • Kubernetes uses CNI plugins (like Flannel, Calico) to manage networking.

    • DNS-based service discovery enables Pods to find Services by name.

  3. Load Balancing

    • Load balancing happens at two levels:

      • Internal Load Balancing: Service distributes traffic to Pods.

      • External Load Balancing: Service type: Load Balancer provisions a cloud load balancer.

Kubernetes ensures high availability and scalability through automatic load balancing of requests.

0
Subscribe to my newsletter

Read articles from Rahul Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rahul Singh
Rahul Singh