Abstract:

This section begins with services. We should not expect Kubernetes Pods to be robust, but assume that containers in pods are likely to fail for various reasons and die. Controllers such as Deployment keep the overall application robust by dynamically creating and destroying pods. In other words, the Pod is fragile, but the application is robust.

Each Pod has its own IP address. When the controller replaces the failed Pod with a new Pod, the new Pod is assigned a new IP address. This raises a question:

If a set of PODS provides an external service (such as HTTP), their IP is likely to change. How does a client find and access this service?

The solution offered by Kubernetes is Service.

Create a Service

Kubernetes Service logically represents a set of pods, which are selected by the label. A Service has its own IP and this IP is immutable. The client only needs to access the IP of the Service, and Kubernetes is responsible for establishing and maintaining the mapping between Service and Pod. No matter how the backend Pod changes, it has no impact on the client because the Service does not change.

For an example, create the following Deployment:

We start three pods and run the HTTPD image. The label is Run: HTTPD. The Service will use this label to select pods.

Pods are assigned individual IP addresses that can only be accessed by containers and nodes in the Kubernetes Cluster.

Next create the Service with the following configuration file:

V1 is the apiVersion of Service.

② Specify the type of the current resource as Service.

③ The Service name is httpD-svc.

④ Selector selects pods whose label is RUN: HTTPD as the back end of the Service.

⑤ Map port 8080 of Service to port 80 of Pod using TCP.

Execute kubectl apply to create Service httpd-svc.

Httpd-svc is assigned to a cluster-IP 10.99.229.179. The BACKEND HTTPD Pod can be accessed from this IP.

Based on the previous port mapping, port 8080 is used here. In addition to the httpD-SVC we created, there is a Service kubernetes that the Cluster uses to access the Kubernetes API Server.

The mapping between HTTPD-SVC and Pod can be seen in Kubectl Describe.

Endpoints list the IP addresses and ports of the three pods. We know that the Pod IP is configured in the container, but where is the Cluster IP configured in the Service? How does Cluster-IP map to Pod IP?

The answer is iptables, which we’ll discuss in the next section.

Books: 1. Play Docker Container Technology in 5 Minutes a day item.jd.com/16936307278…

2. Play OpenStack in 5 Minutes every day item.jd.com/12086376.ht…

Copyright Notice: The content of this article is contributed by Internet users, copyright belongs to the author, the community does not have the ownership, also do not assume the relevant legal responsibility. If you find any content suspected of plagiarism in our community, you are welcome to send an email to [email protected] to report and provide relevant evidence. Once verified, our community will immediately delete the content suspected of infringement.

Use the cloud habitat community APP, comfortable ~

The original link