The difference and association of several kubernets ports (port, targetport, contaierport, hostport, nodeport)

1. These two are generally used in the application yaml description file, and play a role similar to the docker -p option
containerport: the port that the container needs to expose, and the targetPort of the service will be mapped to the containerPort in the pod.
hostport: The host port of the physical machine to which the port exposed by the container is mapped.

2. These two are generally used in service, when the type of service is cluster ip:
port: the port corresponding to clusterip in service
targetport: clusterIP is used as load balancing, the port of the back-end target instance (container). The targetPort corresponds to the containerPort in the pod.

3. This one is generally used in service. The type of service is nodeport:
cluster ip can only be accessed within the cluster (the source and target need to meet two conditions: kube-proxy is running normally, and the cross-host container network communication is normal), and the nodeport will be in The host of each kubelet node opens a port for external access to the application cluster.
4. The difference between hostport and nodeport?
(1) Hostport maps the port of the pod to the host.
(2) Nodeport maps the port of service to each host in the cluster.

Summary of ports
Quickly summarize which ports and labels should match:
Service selector should match the Pod label;
Service targetPort should match the containerPort of the container in the Pod;
Service port can be any number. Multiple Services can use the same port, because different Services assign different IP addresses;
Ingress service.port should match the
Service port; Service name should match the service.name field in Ingress;

Guess you like

Origin blog.csdn.net/qq_34939308/article/details/111033523