五、POD service and communication
Kubernetes in action reading notes

1. Service and port
The service is actually easy to understand. Think about it, how do you manage a group of the same POD? Do you need to know all their IPs, and then manually configure and connect them one by one? Obviously not needed, how to solve this problem, use services, services are actually equivalent to a routing function.
Look at this, there are 3 PODs on the front end, and a Backend, how to make the whole system run normally, using services. The three front-ends set up a front-end service to expose an IP, and the Backend does the same to expose a service, so each part of the connection only focuses on the service IP, regardless of the network information of each POD.
This is the YAML for creating a service, KIND is a Service, and then maps the port of the POD, as well as a label selector. Services can be created with kubectl expose or kubectl create.

Is this fun? It is to test whether the POD can be accessed through the service. It is to exec to a POD first, and then access the ip of this service through curl to see if it can connect to other PODs. It’s very simple.
Let’s talk about ports. A POD can have one port or multiple ports, which is easy to understand.
2. Service Discovery
In fact, it is to use environment variables to connect to this service instead of using a fixed IP. After all, the IP may change. You can select a POD, then kubectl exec kubia-3inly env to list the environment variables, then view the environment variables of this service, and provide other client connections through variables.
3. Endpoint
This guy is more interesting. Look at the picture.
It’s very clear. It’s equivalent to mapping the service to two Endpoints. Can it be understood as load balancing? It’s a bit like that.
4. The method of exposing the service to external clients
Remember, three methods.
-
NodePort
I don’t know the meaning of this setting. What does it mean? It is equivalent to reserving a PORT for all nodes, and then you have two ways to access it. The first is clusterIp: port, the second is nodeIp: port

has three port numbers, the first is the port of the service cluster, The second is the target port of the POD, and the third is the nodePort port.
As you can see from this picture, 30123 is the port of nodeport, through this port Add the IP of node to access the node. -
load balancing method
It uses an external IP from the cloud infrastructure, which is a unique and publicly accessible IP address, through which it is redirected to the service. There is nothing else to say about other feelings, just watch this.

A ready pointer is set, which is to execute the ls command in the container to see if the file exists.

As you can see from this picture, 30123 is the port of nodeport, through this port Add the IP of node to access the node.