Type of service for kubernetes

  kubernetes

Look at the picture.

图片描述

Four types

  • ClusterIP

Use private IP within the cluster-this is the default.

  • NodePort

In addition to using cluster ip, the port of the service is also mapped to a specified internal port of each node, and the internal port of each node mapped is the same.

  • LoadBalancer

Use a ClusterIP & NodePort, but apply to cloud provider for load balancing mapped to the service itself.

  • ExternalName

Map the value of service and externalName (such as foo.bar.example.com ) through CNAME. kube-dns version is required to be 1.7 or above.

Routing

图片描述

  • ClusterIP
    ClusterIP mainly uses iptables in each node node to forward the data sent to the corresponding port of clusterIP to kube-proxy. Then kube-proxy implements a load balancing method inside itself, and can query the address and port of the corresponding pod under this service, and then forward the data to the address and port of the corresponding pod.

  • NodePort
    The principle of nodePort is to open a port on nodeport and import the traffic to the port to kube-proxy, and then the kube-proxy will further direct the traffic to the corresponding node.

  • LoadBalancer
    LoadBalancer is actually the same way as nodePort. See hereexplain. The difference is that LoadBalancer is one step more than nodePort, that is, it can call cloud provider to create LB to guide the node.

doc