👋Introduction
In Kubernetes, Services are essential components that provide stable network identities to Pods.
They abstract away the complexities of dealing with individual Pod IP addresses, making it easier to manage network traffic within your cluster.
Services enable Pods to receive traffic from other Pods, Services, and external clients, thus promoting seamless communication and load distribution.
Now, let's get into the tasks for today.
📃Task 1: Create a Service for your todo-app Deployment
Create a Service definition YAML file: Begin by creating a YAML file named
service.yml
to define your Service for thetodo-app
Deployment.apiVersion: v1 kind: Service metadata: name: todo-app-deployment namespace: todo-app spec: type: NodePort selector: app: todo-app ports: - port: 80 targetPort: 8000
Apply the Service definition: Execute the following command to apply the Service definition to your Kubernetes cluster.
Don't forget to replace
<namespace-name>
with the actual namespace where yourtodo-app
Deployment resides.kubectl apply -f service.yml -n <namespace-name>
Verification: To ensure that the Service is working correctly, access the
todo-app
using the Service's IP and Port within your specified Namespace.kubectl get svc -n <namespace-name>
📚Task 2: Create a ClusterIP Service for accessing the todo-app within the cluster
Create a ClusterIP Service definition YAML file: Now, create another YAML file named
cluster-ip-service.yml
to define a ClusterIP Service for yourtodo-app
Deployment.apiVersion: v1 kind: Service metadata: name: todo-app-clusterip labels: app: todo-app spec: selector: app: todo-app ports: - protocol: TCP port: 8000 targetPort: 8080 type: ClusterIP
Apply the ClusterIP Service definition: Use the following command to apply the ClusterIP Service definition to your Kubernetes cluster within the specified namespace.
kubectl apply -f cluster-ip-service.yml -n <namespace-name>
Verification: To confirm that the ClusterIP Service is functioning correctly, access the
todo-app
from another Pod within the cluster, still in your specified Namespace.Create a YAML file named
test-pod.yml
for a testing pod:apiVersion: v1 kind: Pod metadata: name: test-pod spec: containers: - name: busybox image: busybox command: ['sh', '-c', 'while true; do wget -q -O- clusterip:8000; done']'
Apply the ClusterIP Service definition to your K8s cluster using the command & verify todo-app is running
kubectl apply -f test-pod.yml -n <namespace-name>
📖Task 3: Create a LoadBalancer Service for accessing the todo-app from outside the cluster
Create a LoadBalancer Service definition YAML file: Create a YAML file named
load-balancer-service.yml
to define a LoadBalancer Service for yourtodo-app
Deployment.w you can do it:
apiVersion: v1 kind: Service metadata: name: todo-app-loadbalancer spec: selector: app: todo-app ports: - protocol: TCP port: 80 targetPort: 8000 type: LoadBalancer
Apply the LoadBalancer Service definition: Apply the LoadBalancer Service definition to your Kubernetes cluster within the specified namespace using the following command:
kubectl apply -f load-balancer-service.yml -n <namespace-name>
Verification: To verify the functionality of the LoadBalancer Service, access the
todo-app
from outside the cluster, within your specified Namespace with the command:kubectl get svc -n <namespace-name>
💥Conclusion
Today, you've learned how to work with Services in Kubernetes, which play a pivotal role in ensuring reliable network communication within your cluster. By completing these tasks, you've gained hands-on experience in creating and configuring Services, including ClusterIP and LoadBalancer types. This knowledge will be invaluable as you continue your journey into the world of Kubernetes.
Thank you for joining us on this exciting Day 34 of the 90 Days of DevOps challenge. I hope you found the information helpful and insightful.
Keep building on these concepts, and you'll be well on your way to mastering Kubernetes! 🚀🎉
So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on:
Hashnode: vishaltoyou.hashcode.dev
LinkedIn: linkedin.com/in/vishalphadnis
So, Stay in the loop and stay ahead in the world of DevOps!
Happy learning 🚀🌟📊📚❄