Day 33 : Working with Namespaces and Services in Kubernetes


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 NamespaceUpdate 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.
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.
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.
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.
Subscribe to my newsletter
Read articles from Rahul Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
