In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to analyze Service. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Service is an abstract resource that exposes services running in Pod and provides some load balancing capabilities.
The background of Service
Typically, when we want to deploy the service in Pod, we often create and manage multiple Pod replicas through a Pod controller (such as Deployment). For example, we create three Pod replicas through Deployment, with one nginx service running in each Pod, as shown below:
[root@ecs-d8b6 manifests] # kubectl get pods-o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx-deployment-5f67bd6bb-bvx2w 1 o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx-deployment-5f67bd6bb-bvx2w 1 Running 0 10s 172.17.0.5 127.0.0.1 nginx-deployment-5f67bd6bb-g9kkp 1 Running 0 10s 172.17 . 0.4 127.0.0.1 nginx-deployment-5f67bd6bb-sr2w4 1/1 Running 0 10s 172.17.0.6 127.0.0.1
Kubernetes assigns an IP address to each Pod, and Pod uses this IP address to communicate with the outside world. In the above example, the IP addresses of the three Pod are 172.17.0.5, 172.17.0.4, and 172.17.0.6 respectively. Users or other Pod in the cluster can use these IP addresses to access the nginx service, as shown below:
[root@ecs-d8b6 manifests] # curl 172.17.0.4...Welcome to nginx!...
This deployment mode can only ensure the basic service capacity, from the actual user experience point of view, there are some unavoidable problems.
First of all, the IP address of Pod is randomly assigned, and other Pod cannot know the IP address of the service in advance.
Second, Pod is a "perishable" resource that can be recreated or dispatched to other nodes at any time, and each time a new random IP address is obtained.
Third, there is no connection between multiple Pod replicas. If the user needs to provide load balancing for the service, the user needs to manage these Pod dynamically and handle the traffic distribution.
Service is a solution to address these pain points. It manages a set of Pod replicas, providing reliable access and load balancing capabilities for these replicas.
Service configuration
Like other objects (such as Pod), Service is also a REST object. You can create a Service object through the corresponding API or configuration file. A simple Service configuration file is as follows:
ApiVersion: v1kind: Servicemetadata: name: nginx-servicespec: selector: app: nginx ports:-protocol: TCP port: 80 targetPort: 80
This configuration creates a Service object called nginx-service, which is mainly configured as follows:
Spec.selector: specifies the Pod selector, which will find the Pod containing the app: nginx tag as the traffic distribution object
Spec.ports: list of ports exposed by the Service. Multiple ports can be exposed.
Spec.ports.protocol: the IP protocol corresponding to this port, which supports TCP, UDP and SCTP
Spec.ports.port: the port number that the port is exposed to
Spec.ports.targetPort: the port exposed by the backend Pod
To put it simply, Service uses spec.selector to find Pod, and "aggregates" the services provided by these Pod to provide a unified entry. When creating a Service object, Kubernetes assigns an IP (called Cluster IP) to Service by default. For example, 10.0.0.165 Cluster IP Service provides services through this IP. When the request traffic arrives, it forwards the traffic to the backend Pod and provides certain load balancing capabilities. The overall workflow is as follows:
Accessing the Cluster IP of Service is the same as directly accessing the IP address of Pod, but you can use Service to mask the details of the backend Pod and provide a fixed access entry. When the backend Pod changes, the Service will automatically update the forwarding list.
This is the end of the analysis on how to carry out Service. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.