Day 34 Working with Services in Kubernetes 🌐

You've made it to Day 34 of your Kubernetes learning journey! Yesterday, you deployed an application in Kubernetes, and today, we’re taking things further by setting up Services to manage how our app can be accessed. Let's dive in!
🌟 What Are Services in Kubernetes?
In Kubernetes (K8s), Services are objects that act like a bridge, providing stable network identities to Pods (the smallest deployable units in Kubernetes). They help your app receive traffic, regardless of Pod IP changes, and ensure seamless communication between Pods, Services, and even external clients.
🧠 In Simple Terms: Imagine Services as doors that let you reach your app without worrying about which room (Pod) it's in. Services manage this for you, so traffic always reaches the right place!
🔧 Hands-On Tasks: Setting Up Services for Your todo-app
Let's get practical! We’ll create and use three types of Kubernetes Services to access the todo-app deployed on Day 32:
Task 1: Create a Service for Your todo-app Deployment 🚪
here the project link
git clone https://github.com/LondheShubham153/django-todo-cicd.git
This Service will give your app a stable identity within the cluster.
Define the Service: Create a YAML file named
service.ymlwith this basic setup:apiVersion: v1 kind: Service metadata: name: todo-app-service spec: selector: app: todo-app ports: - protocol: TCP port: 80 targetPort: 8080Apply the Service Definition: Use the following command to apply the Service to your Kubernetes cluster (replace
<namespace-name>with your actual namespace):kubectl apply -f service.yml -n <namespace-name>Verify the Service: Check if your Service is working by accessing the
todo-appusing the Service's IP and port:kubectl get svc -n <namespace-name>
Task 2: Create a ClusterIP Service for Internal Access 🔄
ClusterIP is the default Service type that only allows access within the cluster.
Define the ClusterIP Service: Create a YAML file named
cluster-ip-service.yml:apiVersion: v1 kind: Service metadata: name: todo-app-clusterip-service spec: type: ClusterIP selector: app: todo-app ports: - protocol: TCP port: 80 targetPort: 8080Apply the ClusterIP Service Definition:
kubectl apply -f cluster-ip-service.yml -n <namespace-name>Verify the ClusterIP Service: Access the
todo-appfrom another Pod within the cluster. You can use the Pod’s terminal to confirm internal access:kubectl exec -it <pod-name> -n <namespace-name> -- curl todo-app-clusterip-service
Task 3: Create a LoadBalancer Service for External Access 🌍
A LoadBalancer Service allows your app to be accessed from outside the cluster.
Define the LoadBalancer Service: Create a YAML file named
load-balancer-service.yml:yamlCopy codeapiVersion: v1 kind: Service metadata: name: todo-app-loadbalancer-service spec: type: LoadBalancer selector: app: todo-app ports: - protocol: TCP port: 80 targetPort: 8080Apply the LoadBalancer Service Definition:
kubectl apply -f load-balancer-service.yml -n <namespace-name>Verify the LoadBalancer Service: Once the LoadBalancer is set up, access the
todo-appfrom outside the cluster using the external IP provided:kubectl get svc -n <namespace-name>
🚀 Note: LoadBalancer might not work on Minikube, as it's designed for cloud environments like AWS or GCP. In Minikube, you can use the
minikube servicecommand to access LoadBalancer Services.
📝 Summary
Here's what we've covered:
Kubernetes Services provide stable access to your app within and outside the cluster.
We created three types of Services for your
todo-app:Standard Service for basic access.
ClusterIP Service for internal access only.
LoadBalancer Service for external access.
👏 Congratulations on Completing Day 34!
You’re becoming a Kubernetes pro! Keep practicing and exploring more about Services in Kubernetes. The more you work with these concepts, the more confident you'll become.




