In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The editor of this article introduces in detail "how to deal with load balancing under grpc-java K8s". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to deal with load balancing under grpc-java K8s" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.
Preface
Because grpc is long-connected, load balancer is not as easy to handle as rest interface. Common grpc load balancing methods are divided into two categories, one is client-side implementation of load logic, and the other is proxy-side implementation of load logic, which is transparent to the client side. In the containerized network environment, there are two common implementation paths for load balancing on the grpc-java client side.
Current situation
In the K8s network environment, a grpc service, under the same namespace, can be accessed directly through service, while different namespace can be accessed through service.namespace. However, it has been verified that this directly connected method cannot achieve load balancing, which means that no matter how many pod instances are enabled on the server, the client can only connect to one pod. Therefore, when the number of clients and servers is not equal, the traffic to the server side will be very uneven. If the number is equal, the situation is slightly better. This test only tests the grpc service of java linked java. The actual invocation scenario of the production environment will be more complex, including the mutual invocation of php, go and java grpc services.
Load balancing solution 1. Client-side dns mode
The mode of dns is the lowest cost for grpc-java to realize complex equilibrium transformation. It should also be the most common, and grpc in all languages should be supported. There are two main changes.
1. Change the spec.clusterIP of Service to "None", such as:
ApiVersion: v1kind: Servicemetadata: namespace: tap-prod name: queuing-rpc labels: app: queuing-rpcspec: clusterIP: None ports:-port: 8030 targetPort: 8030 name: grpc selector: app: queuing-rpc
After modification, the name of service can be resolved to the ip list of pod.
2. Add dns protocol to the configured grpc link protocol header, such as:
Grpc.client.store.address = dns:///store-rpc:8020
II. Client registry mode
Compared with the dns model, the client registry model is relatively complex to implement, but it is more flexible. With the registry, everything related to service governance can be done. However, in multilingual scenarios, the popularity of this approach will be more difficult, no matter which registry implementation you choose, it must be implemented in other languages as well. Here is only a brief description of the implementation of grpc-java.
. The grpc-java client provides extension classes for service registration discovery, such as NameResolver, NameResolverProvider, NameResolverRegistry, and so on. Combined with registry ZooKeeper/Etcd/Consul/Eureka, it is easy to implement a registry-based grpc with service governance.
Third, the agent takes the ingress
Nginx-ingress-controller has supported grpc traffic proxy since version 0.30.0. It has been tested that in nginx-ingress proxy mode, grpc traffic is responsible for balancing. This change is also relatively simple. The server only needs to add a new ingress proxy grpc traffic, and the client link is insensitive and does not need to make any changes. Because of the layer of agents, the performance will be worse than that of dns mode.
ApiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata: namespace: tap-prod name: store-rpc annotations: kubernetes.io/ingress.class: nginx-intranet-grpc nginx.ingress.kubernetes.io/backend-protocol: "GRPC" spec: rules:-host: store-rpc.xx.com http: paths:-backend: serviceName: store-rpc servicePort: 8020 IV, agent service mesh
Service grid architecture such as istio needs to be introduced. This model, which is very friendly to the multilingual microservice environment, can shield the implementation details of various language basic service governance, and should be the ultimate goal solution.
After reading this, the article "how to deal with load balancing under grpc-java K8s" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
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.