Day 33 Task: Working with Namespaces and Services in Kubernetes

What are Namespaces and Services in k8s
In Kubernetes, Namespaces are used to create isolated environments for resources. Each Namespace is like a separate cluster within the same physical cluster. Services are used to expose your Pods and Deployments to the network.
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.yml 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.
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-deployment
namespace: django-app
labels:
app: todo-app
spec:
replicas: 3
selector:
matchLabels:
app: todo-app
template:
metadata:
labels:
app: todo-app
spec:
containers:
- name: todo-app
image: pooja-bhavani/django-todo-cicd
ports:
- containerPort: 8000
kubectl create namespace django-app
kubectl delete pods <your pods names>
kubectl apply -f deployment.yaml -n django-app
kubectl get namespace
Task 2:
Services:
Services provide a consistent way to access and connect to groups of Pods (instances of an application) within a Kubernetes cluster.
Types of Services:
ClusterIP: Exposes the service only within the cluster.
NodePort: Exposes the service on each node's IP at a specific port.
LoadBalancer: Creates an external load balancer in the cloud provider, routing external traffic to the service.
ExternalName: Maps the service to a DNS name.
Load Balancing:
Role: Load balancing ensures even distribution of network traffic across multiple Pods or instances of an application.
How It Works: When multiple instances of an application (Pods) exist, Kubernetes' built-in load balancer intelligently distributes incoming traffic among these instances, optimizing performance and preventing overload on any single Pod.
Networking:
Kubernetes Network Model: Each Pod in Kubernetes has a unique IP address within the cluster, allowing direct communication between Pods regardless of the node they're on.
Container-to-Container Communication: Pods within the same node can communicate via localhost, while Pods on different nodes communicate using the Pod's IP address.
Subscribe to my newsletter
Read articles from Pooja Bhavani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Pooja Bhavani
Pooja Bhavani
Hi, I am Pooja Bhavani, an enthusiastic DevOps Engineer with a focus on deploying production-ready applications, infrastructure automation, cloud-native technologies. With hands-on experience across DevOps Tools and AWS Cloud, I thrive on making infrastructure scalable, secure, and efficient. My journey into DevOps has been fueled by curiosity and a passion for solving real-world challenges through automation, cloud architecture, and seamless deployments. I enjoy working on projects that push boundaries whether it's building resilient systems, optimizing CI/CD pipelines, or exploring emerging technologies like Amazon Q and GenAI. I'm currently diving deeper into platform engineering and GitOps workflows, and I often share practical tutorials, insights, and use cases from my projects and experiences. ✨ Let’s connect, collaborate, and grow together in this ever-evolving DevOps world. Open to opportunities, ideas, and conversations that drive impactful tech!