avatarAshish Patel

Summary

The web content provides an overview of the four types of Kubernetes services: ClusterIP, NodePort, LoadBalancer, and ExternalName, explaining their characteristics, use cases, and examples.

Abstract

Kubernetes services are essential components that define how pods communicate with each other and with the outside world. The article introduces four primary service types in Kubernetes: ClusterIP, which is the default and provides internal cluster communication; NodePort, which extends ClusterIP by exposing a service on a static port on each node; LoadBalancer, which integrates NodePort with cloud-based load balancers for external access; and ExternalName, which maps a service to an external DNS name. Each service type serves specific use cases, such as inter-service communication, external connectivity, cloud provider integration, and access to external datastores. The article also touches on Ingress as an additional method to expose services and provides examples and links to further reading on the topic.

Opinions

  • The author suggests that ClusterIP is the most common service type due to its default status and suitability for internal communication within a cluster.
  • NodePort is presented as a flexible option for external access, allowing for custom load balancing solutions or direct node IP exposure.
  • The LoadBalancer service type is highlighted as particularly useful when hosting a Kubernetes cluster on a cloud provider, leveraging the provider's load balancer for external traffic management.
  • ExternalName services are recommended for integrating external resources, such as databases, into Kubernetes applications without setting up a proxy.
  • Ingress is mentioned as a powerful alternative for managing external access to multiple services within a cluster, offering consolidated routing rules and the ability to expose services under a single IP address.
  • The author promotes the use of an AI service, ZAI.chat, as a cost-effective alternative to ChatGPT Plus (GPT-4), indicating a preference for this tool based on its performance and affordability.

Kubernetes — Service Types Overview

Introduction to Service types in K8s — Types of Kubernetes Services.

Kubernetes — Service Types

TL;DR

There are four types of Kubernetes services — ClusterIP, NodePort, LoadBalancer and ExternalName. The type property in the Service's spec determines how the service is exposed to the network.

Read about Kubernetes Services and Ingress

1. ClusterIP

  • ClusterIP is the default and most common service type.
  • Kubernetes will assign a cluster-internal IP address to ClusterIP service. This makes the service only reachable within the cluster.
  • You cannot make requests to service (pods) from outside the cluster.
  • You can optionally set cluster IP in the service definition file.

Use Cases

  • Inter service communication within the cluster. For example, communication between the front-end and back-end components of your app.

Example

2. NodePort

  • NodePort service is an extension of ClusterIP service. A ClusterIP Service, to which the NodePort Service routes, is automatically created.
  • It exposes the service outside of the cluster by adding a cluster-wide port on top of ClusterIP.
  • NodePort exposes the service on each Node’s IP at a static port (the NodePort). Each node proxies that port into your Service. So, external traffic has access to fixed port on each Node. It means any request to your cluster on that port gets forwarded to the service.
  • You can contact the NodePort Service, from outside the cluster, by requesting :.
  • Node port must be in the range of 30000–32767. Manually allocating a port to the service is optional. If it is undefined, Kubernetes will automatically assign one.
  • If you are going to choose node port explicitly, ensure that the port was not already used by another service.

Use Cases

  • When you want to enable external connectivity to your service.
  • Using a NodePort gives you the freedom to set up your own load balancing solution, to configure environments that are not fully supported by Kubernetes, or even to expose one or more nodes’ IPs directly.
  • Prefer to place a load balancer above your nodes to avoid node failure.

Example

3. LoadBalancer

  • LoadBalancer service is an extension of NodePort service. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.
  • It integrates NodePort with cloud-based load balancers.
  • It exposes the Service externally using a cloud provider’s load balancer.
  • Each cloud provider (AWS, Azure, GCP, etc) has its own native load balancer implementation. The cloud provider will create a load balancer, which then automatically routes requests to your Kubernetes Service.
  • Traffic from the external load balancer is directed at the backend Pods. The cloud provider decides how it is load balanced.
  • The actual creation of the load balancer happens asynchronously.
  • Every time you want to expose a service to the outside world, you have to create a new LoadBalancer and get an IP address.

Use Cases

  • When you are using a cloud provider to host your Kubernetes cluster.

This type of service is typically heavily dependent on the cloud provider.

Example

4. ExternalName

  • Services of type ExternalName map a Service to a DNS name, not to a typical selector such as my-service.
  • You specify these Services with the `spec.externalName` parameter.
  • It maps the Service to the contents of the externalName field (e.g. foo.bar.example.com), by returning a CNAME record with its value.
  • No proxying of any kind is established.

Use Cases

  • This is commonly used to create a service within Kubernetes to represent an external datastore like a database that runs externally to Kubernetes.
  • You can use that ExternalName service (as a local service) when Pods from one namespace to talk to a service in another namespace.

Example

Ingress

You can also use Ingress to expose your Service. Ingress is not a Service type, but it acts as the entry point for your cluster. It lets you consolidate your routing rules into a single resource as it can expose multiple services under the same IP address.

View more from DevOps Mojo

Happy Learning!!!

Kubernetes
Kubernetes Service
Kubernetes Networking
K8s
DevOps
Recommended from ReadMedium