Brief Overview on Services in kubernetes

okay so what is Services in k8s .

In the Kubernetes ecosystem, Services are fundamental components that facilitate seamless communication and networking within distributed applications deployed in containerized environments. When dealing with complex applications comprised of multiple interconnected parts, such as a frontend, backend, database, and Redis server running in separate containers or pods, Services act as the glue that binds these components together. They provide a consistent endpoint for accessing the application from outside the Kubernetes cluster, allowing users or external systems to interact with the frontend seamlessly. Internally, Services enable reliable communication between different parts of the application by abstracting away the underlying network complexity. By defining a Service for each component, Kubernetes ensures that traffic is efficiently routed to the appropriate pods based on labels and selectors, regardless of their dynamic nature. This decoupling of network configuration from individual workload instances enhances scalability, resilience, and maintainability of the application architecture. Additionally, Kubernetes Services support various networking modes, including ClusterIP for internal communication, NodePort for exposing services on a specific port of each cluster node, and LoadBalancer for integrating with external load balancers or cloud providers. Overall, Services play a pivotal role in enabling the robust and reliable operation of modern containerized applications in Kubernetes clusters, fostering agility, scalability, and interoperability in cloud-native environments.

Imagine you have your own laptop with the IP address 192.168.1.10, and there's a Kubernetes node with the IP address 192.168.1.2. Inside this node, there's a pod with a different IP address, say 10.244.0.2, running an application. Currently, accessing this application requires first SSHing into the node and then accessing the container via HTTP requests. However, this method poses challenges for users outside the network who can't directly access the node. This accessibility issue is effectively resolved by Kubernetes Services.

what is Service ?

In Kubernetes a service is indeed an object Just like Pod , Deployment and Replicaset .

Definition: A service in Kubernetes is an abstract way to expose an application running on a set of pods as a network service. It provides a consistent and stable endpoint (IP address and port) that other applications or services can use to access the pods that make up the service.

so using services you dont need to ssh into the node and then get the running application .

so one of the application of services in k8s is to listen to the port of a node and then forward a request to a port of a pod running the web application . This type of service is know as Nodeport Service as its listen on a node of a port .

Types of Services in k8s

  1. NodePort

    In Kubernetes, a NodePort service is a type of service that exposes an application running on a set of pods to the outside world by mapping a static port on each node in the cluster to the service. This allows external traffic to reach the service on that port, which is then forwarded to one of the pods selected by the service.

    Definition:

    • When you define a service with the type NodePort in Kubernetes, the Kubernetes control plane assigns a static port (NodePort) from a predefined range (typically between 30000-32767) on each node in the cluster.

    • The service listens on this NodePort on each node, forwarding incoming traffic to the pods that are part of the service.

  1. ClusterIp

    In Kubernetes, ClusterIP is a type of service that exposes an application running on a set of pods internally within the cluster. It provides a stable, internal IP address that other applications or services within the same Kubernetes cluster can use to access the pods that make up the service.

    • Definition:

      • When you define a service with the type ClusterIP in Kubernetes, the Kubernetes control plane assigns an internal IP address (ClusterIP) to the service.

      • The service listens on this ClusterIP internally within the Kubernetes cluster, making it accessible only from within the cluster.

  1. LoadBalancer

    a LoadBalancer service is a type of service that exposes an application running on a set of pods to the outside world by provisioning a cloud provider's load balancer. This load balancer distributes incoming traffic across the pods that are part of the service, ensuring high availability, scalability, and fault tolerance.

    • Definition:

      • When you define a service with the type LoadBalancer in Kubernetes, the Kubernetes control plane interacts with the cloud provider's API to provision a load balancer resource.

      • The cloud provider assigns an external IP address to the load balancer, which serves as the entry point for incoming traffic from external clients or users.