Working with Services in Kubernetes

Working with Services in Kubernetes

In Kubernetes, a service is an abstraction that represents a logical set of pods (or a single pod) and a policy by which to access them. Pods are the smallest deployable units in Kubernetes, and they can be thought of as individual containers that run in the same network space and share the same resources.

A service provides a stable IP address and DNS name for a set of pods, allowing other pods or services to communicate with them. When a pod is created or deleted, the service automatically updates its endpoint list to reflect the current state of the pods. This means that applications can always connect to the service using the same IP address and DNS name, even if the pods behind the service are constantly changing.

Services can be configured to expose pods within the same cluster or outside of the cluster, depending on the needs of the application. There are four types of services in Kubernetes:

  1. ClusterIP: Exposes the service on a cluster-internal IP address, making it available only within the cluster.

  2. NodePort: Exposes the service on a static port on each worker node in the cluster, making it available outside the cluster.

  3. LoadBalancer: Exposes the service externally using a cloud provider's load balancer.

  4. ExternalName: Maps a service to a DNS name, allowing applications to refer to it by name rather than by IP address.

Task:

  • Create a Service for your todo-app Deployment from Day-32

  • Create a Service definition for your todo-app Deployment in a YAML file.

  • Apply the Service definition to your K8s (minikube) cluster using the kubectl apply -f service.yml -n <namespace-name> command.

  • Verify that the Service is working by accessing the todo-app using the Service's IP and Port in your Namespace.

minikube setup

created service.yml file

  • Task-2:

  • Create a ClusterIP Service for accessing the todo-app from within the cluster

  • Create a ClusterIP Service definition for your todo-app Deployment in a YAML file.

  • Apply the ClusterIP Service definition to your K8s (minikube) cluster using the kubectl apply -f cluster-ip-service.yml -n <namespace-name> command.

  • Verify that the ClusterIP Service is working by accessing the todo-app from another Pod in the cluster in your Namespace.

Task-3:

  • Create a LoadBalancer Service for accessing the todo-app from outside the cluster

  • Create a LoadBalancer Service definition for your todo-app Deployment in a YAML file.

  • Apply the LoadBalancer Service definition to your K8s (minikube) cluster using the kubectl apply -f load-balancer-service.yml -n <namespace-name> command.

  • Verify that the LoadBalancer Service is working by accessing the todo-app from outside the cluster in your Namespace.

THAT'S ALL FOR TODAY'S LEARNING I HOPE YOU LEARN SOMETHING FROM THIS BLOG