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 Yuvraj Nath Chouhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Yuvraj Nath Chouhan
Yuvraj Nath Chouhan
🚀 Aspiring DevOps & DevSecOps Engineer | Cloud DevOps (Azure & AWS) | Automation & Security Champion | Passionate Learner🌐 Hi, I’m Yuvraj! 🔥 I'm embarking on an exciting journey in the world of DevOps & DevSecOps, armed with hands-on expertise and a drive to excel. From automating tasks to building robust CI/CD pipelines, I’m dedicated to turning complex challenges into efficient and secure solutions. What I Bring to the Table: ●Linux & Shell Scripting 🖥️ Automating processes and mastering command-line operations. ●Git & Git Branching 🔀 Seamless version control for effective collaboration. ●Build Tools 🔧 (Maven & npm) Crafting stable builds for quality software. ●CI/CD Tools 🚄 (Jenkins, GitHub Actions, Azure DevOps, GitLab CI/CD) Ensuring smooth & automated deployments. ●Security in DevOps 🛡️ Embedding security at every stage to safeguard development processes. ●Artifact Management 📦 (Nexus & Azure Artifacts) Managing software versions efficiently. ●Containerization & Orchestration 🐳⎈ (Docker & Kubernetes) Deploying scalable, agile applications. ●Infrastructure as Code (IaC) 📜 (Terraform & Ansible) Automating environment provisioning. ●Monitoring & Troubleshooting 🔍 Keeping systems in check with proactive issue resolution. ●Real-world & Corporate Projects 🌟 Hands-on experience with practical implementations. ✨ Always eager to learn, collaborate, and innovate! ✨ I’m ready to transform my academic knowledge and project experiences into real-world impact. Let’s connect and explore how we can drive meaningful change together! 🤝