What are the Service types in K8S?

In Kubernetes (or K8s for short), Service is an abstract method of defining access to Pods, which provides load balancing and network proxy functionality. Here are some of the main types of Kubernetes Services:

1. ClusterIP (default type).

- Creates a virtual IP that is accessible only within the cluster.

- With this IP address, Kubernetes routes traffic to a set of Pods associated with the Service.

- This type of Service is best suited for applications that only need to be invoked from within the cluster.

2. NodePort

- Expose a static port (in the range of 30000-32767) on each node and any traffic requested to this port is forwarded to the associated Pod behind the Service.

- Using the NodePort service you can access the Service from outside the cluster via <Node IP>:<NodePort>.

3. LoadBalancer

- On top of NodePort, further create a load balancer resource of the cloud provider and configure it to point to the NodePort service on the backend.

- The load balancer is assigned a public IP address that allows direct access to the Kubernetes service from the Internet.

- The level of support for LoadBalancer may vary between cloud environments, and in some local or homegrown environments it may be necessary to use Ingress or other means to implement similar functionality.

4. ExternalName

- Instead of creating an in-cluster proxy, returns a CNAME record pointing to the specified DNS name.

- This type of service is mainly used to map an in-cluster service to a service outside the cluster.

- When a client queries a Service of type ExternalName, the DNS name of an external service is returned instead of the IP inside the cluster.

In summary, it is also possible to use these Service types in combination to meet specific needs. For example, a NodePort or LoadBalancer can be created on the ClusterIP to fulfill both internal and external access needs. It should be noted that each Service type has its own application scenario, so you should choose the appropriate type according to the specific application requirements and network environment when creating a Service.

Privacy    |    Terms of use