In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces you how to experience the functions provided by Service. The content is very detailed. Interested friends can refer to it for reference. I hope it can help you.
create
When creating a Service object, Kubernetes will find a Pod with the specified label according to spec.selector. If it finds a Pod, it will maintain a set of topology relationships. If it cannot be found, it will not automatically create a Pod (there is no Pod template in the configuration). Therefore, the Pod object used in this example needs to be created separately. Before we start, assume that we have created a set of Pod objects with the label app: nginx using the configuration used in the previous introduction of Deployment. These Pods provide services to the outside through port 80.
First, we save the following configuration to a file named service.yaml:
apiVersion: v1kind: Servicemetadata: name: nginx-servicespec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80
Then, create the Service object:
[root@ecs-d8b6 manifests]# kubectl create -f service.yaml service/nginx-service created
Then look at the Service object you just created:
[root@ecs-d8b6 manifests]# kubectl get services nginx-service -o wideNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORnginx-service ClusterIP 10.0.0.83 80/TCP 56s app=nginx
The fields in the command line output have the following meanings:
NAME: Name of Service object, corresponding to metadata.name in configuration;
TYPE: Service type, default is ClusterIP type, more types will be described in later chapters;
CLUSTER-IP: Auto-assigned Cluster IP;
EXTERNAL-IP: external IP address, used to receive external traffic of the cluster, described in detail later when introducing Service type;
PORT(S): List of ports exposed by Service. In this example, only one port is exposed, corresponding to spec.ports in the configuration;
AGE: Time elapsed since creation;
SELECTOR: label selector, Service View backend Pods according to this selector, corresponding to spec.selector in configuration.
Kubernetes currently supports multiple Service types to cope with different usage scenarios:
Cluster IP: Service exposes services through a Cluster IP that is accessible only within the cluster;
NodePort: Service exposes services through a port on a Node;
LoadBalancer: Service exposes services through a Load Balancer provided by a specific cloud vendor;
ExternalName: Service exposes only one domain name;
View Pod Topology
Although Service uses selector to find Pods, the Pod information found is not recorded directly in Service objects, but in an Endpoints object. Further, when creating Service objects, Kubernetes also creates an Endpoints object with the same name to record the backend Pod topology. Endpoints are discussed in detail in subsequent chapters, but this is only a preliminary introduction.
View the Endpoints object created with Service:
[root@ecs-d8b6 manifests]# kubectl get endpoints nginx-service NAME ENDPOINTS AGEnginx-service 172.17.0.4:80,172.17.0.5:80,172.17.0.6:80 20m
As you can see, the Endpoints object records all the Pod addresses that Service matches.
access Service
Inside the cluster, you can directly access the Cluster IP of the Service, and the traffic will be automatically forwarded to a Pod at the backend:
[root@ecs-d8b6 manifests]# curl 10.0.0.83... Welcome to nginx!... update
When you update the spec.selector of a Service, Kubernetes automatically looks for Pods according to the new spec.selector configuration and updates the Endpoints object.
Use kubectl edit service nginx-service to modify Service and specify a spec.selector that does not match any Pod. You can see that the Pod topology information in the Endpoints object will disappear accordingly, as follows:
[root@ecs-d8b6 manifests]# kubectl get endpoints nginx-service NAME ENDPOINTS AGEnginx-service 31m Deleted
When you delete a Service object, the Endpoints object created automatically with the creation of the Service object is also deleted, and the backend Pod is not deleted, it is still managed by the corresponding Pod controller.
[root@ecs-d8b6 manifests]# kubectl delete service nginx-service service "nginx-service" deleted[root@ecs-d8b6 manifests]# kubectl get endpoints nginx-serviceError from server (NotFound): endpoints "nginx-service" not found[root@ecs-d8b6 manifests]# kubectl get pods NAME READY STATUS RESTARTS AGEnginx-deployment-5f67bd6bb-9nspj 1/1 Running 0 37mnginx-deployment-5f67bd6bb-hl8xw 1/1 Running 0 37mnginx-deployment-5f67bd6bb-pkv7h 1/1 Running 0 37m on how to experience the functions provided by Service to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
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.