In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use K8s to achieve service registration and discovery". The content in the article is simple and clear, and it is easy to learn and understand. let's study and learn how to use K8s to achieve service registration and discovery.
1. K8s component configMapkube-apiserverscheduleretcdcontrollerkube-proxy
K8s is mainly responsible for providing cluster internal service discovery and load balancing for Service through kube-proxy. It is not only a load balancer within K8s cluster, but also a distributed proxy server, which has one on each node of K8s. This design reflects its scalability advantages. The more nodes that need to access the service, the more kube-proxy provides load balancing capacity, and the number of highly available nodes also increases. The LB of services in the cluster is implemented through the "ClusterIP" of K8s service. Of course, if you need to access all the pod applications with the same function corresponding to Service outside the cluster, you can do so in another way of K8s service: "NodePort".
two。 Implementation of micro-service load balancing based on Service
In the Java language, or other languages, it is usually necessary to do a lot of heavy components to implement the LB of services. For example: Dubbo, SpringCloud, even SpringCloudAlibaba, etc. Of course, for Python, Go and other languages, there is also its Restful API, so it will also integrate standard proxy plug-ins to do traditional LB. But with the arrival of the cloud native era, service containerization makes micro-service access better. The LB provided by K8s Service, that is, load balancer with no language margin, does not need to consider any language obstacles. As long as it is a general Restful API, you can use service to handle the LB between micro-services within the cluster.
In K8s cluster, if it is accessed internally, it can be accessed simply through servicename. For example:
ApiVersion: v1
Kind: Service
Metadata:
Name: web-server-service
Namespace: default
Spec:
Ports:
-name: web-server
Port: 80
TargetPort: web-server-port
Selector:
App: web-server
Match the service with the service pod through selector, and create a micro-service service. The default form is ClusterIP, and you can access the backend pod corresponding to the service as follows:
Curl http://$service_name.$namespace.svc.cluster.local:$service_port/api/v1/***
Here, K8s simulates a cluster IP and uses kube-proxy to provide service discovery and load balancing in cluster for service. The functions of kube-proxy are described above.
Name: web-server-service
Namespace: default
Type: ClusterIP
IP: 20.16.249.134
Port: 80/TCP
TargetPort: 80/TCP
Endpoints: 20.162.35.223:80
Session Affinity: None
Events:
3. High availability case 3.1 traditional micro-service request case
In the traditional micro-service, there are many micro-service architectures built in different languages, which are generally accessed directly through the http protocol. In the same language, there will be an integrated framework pattern to implement the micro-service architecture. Such as: Dubbo, Springcloud in Java, but its tedious framework structure leads to heavy service.
3.2 Interoperability of cross-language microservices
In the K8s cluster, kube-proxy is combined with some functional components such as service to realize the invocation between micro-services, no matter in the same language or across languages. Will be well handled, including the implementation of high availability as well as load balancing, service governance and so on.
Pod in any K8s cluster can access other pod services through http protocol:
Root@rest-server-ver2-ds-vcfc7:/usr/src/app# curl http://web-server-service.kube-system.svc.cluster.local:80/api/v1/healthz
{
"status": {
"code": 0
"msg": "success"
}
"data": "success"
} root@rest-server-ver2-ds-vcfc7:/usr/src/app# thank you for your reading, the above is the content of "how to use K8s to achieve service registration and discovery". After the study of this article, I believe you have a deeper understanding of how to use K8s to achieve service registration and discovery, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.