What are the different types of Kubernetes services?
Kubernetes Services are an abstract way to expose an application running on a set of Pods as a network service. They provide a stable IP address and DNS name for a set of Pods, enabling communication both within and outside the cluster. There are four primary types of Kubernetes Services, each designed for different exposure scenarios.
1. ClusterIP
This is the default service type. A ClusterIP service exposes the service on an internal IP address within the cluster. It makes the service only reachable from within the cluster. This type is suitable for services that you want to expose to other applications running inside your cluster.
2. NodePort
A NodePort service exposes the service on each Node's IP at a static port (the NodePort). A ClusterIP service is automatically created, and the NodePort service will route to it. This means that you can contact the service from outside the cluster by requesting <NodeIP>:<NodePort>. This type is often used for development or testing environments, or when direct access to a specific port on each node is required.
3. LoadBalancer
A LoadBalancer service exposes the service externally using a cloud provider's load balancer. A NodePort service is automatically created, which then routes to a ClusterIP service. The cloud provider creates an external load balancer that automatically routes traffic to the NodePort. This type is ideal for publicly exposing services to the internet, as it provides a stable external IP address and distributes incoming traffic across multiple nodes.
4. ExternalName
An ExternalName service maps the service to the contents of the externalName field (e.g., my.database.example.com) by returning a CNAME record. No proxying of any kind is set up. This type is used to expose a service that resides outside of the Kubernetes cluster (e.g., a database hosted externally) to services within the cluster using a familiar Kubernetes service name.