当前位置: 首页 > news >正文

K8s中gRpc通信负载均衡失效

上篇文章在做 整合K8s+SpringCloudK8s+SpringBoot+gRpc 时,发现K8s中使用gRpc通信,负载均衡功能失效

查了下gRpc的最佳实践,找到这里

Load balancing

Some load balancers don't work effectively with gRPC. L4 (transport) load balancers operate at a connection level, by distributing TCP connections across endpoints. This approach works well for loading balancing API calls made with HTTP/1.1. Concurrent calls made with HTTP/1.1 are sent on different connections, allowing calls to be load balanced across endpoints.

Because L4 load balancers operate at a connection level, they don't work well with gRPC. gRPC uses HTTP/2, which multiplexes multiple calls on a single TCP connection. All gRPC calls over that connection go to one endpoint.

There are two options to effectively load balance gRPC:

  • Client-side load balancing

  • L7 (application) proxy load balancing

Note

Only gRPC calls can be load balanced between endpoints. Once a streaming gRPC call is established, all messages sent over the stream go to one endpoint.

Client-side load balancing

With client-side load balancing, the client knows about endpoints. For each gRPC call, it selects a different endpoint to send the call to. Client-side load balancing is a good choice when latency is important. There's no proxy between the client and the service, so the call is sent to the service directly. The downside to client-side load balancing is that each client must keep track of the available endpoints that it should use.

Lookaside client load balancing is a technique where load balancing state is stored in a central location. Clients periodically query the central location for information to use when making load balancing decisions.

For more information, see gRPC client-side load balancing.

Proxy load balancing

An L7 (application) proxy works at a higher level than an L4 (transport) proxy. L7 proxies understand HTTP/2, and are able to distribute gRPC calls multiplexed to the proxy on one HTTP/2 connection across multiple endpoints. Using a proxy is simpler than client-side load balancing, but can add extra latency to gRPC calls.

There are many L7 proxies available. Some options are:

  • Envoy - A popular open source proxy.

  • Linkerd - Service mesh for Kubernetes.

  • YARP: Yet Another Reverse Proxy - An open source proxy written in .NET.

上面也给出了解决方案,我们采用第二种 Linkerd 来做,这是个Service Mesh的一个实现,类似于Istio,但要比Istio更轻量级,我们这里只是选择一个代理而已,之后可能会集成Trace和监控的功能,所以功能上不用太丰富,而是要简单轻量,还要快,毕竟是代理嘛。

一、安装Linkerd

https://linkerd.io/2.12/getting-started/

安装完成之后会自动打开 dashboard

二、把应用交给Linkerd 托管

kubectl get deploy service-consumer -n service-k8s-demo -o yaml \| linkerd inject - \| kubectl apply -f -kubectl get deploy service-provider -n service-k8s-demo -o yaml \| linkerd inject - \| kubectl apply -f -

三、我这里有两个服务 service-consumer 和 service-provider,每个服务都有3个副本,再测试下负载均衡,发现已经生效了。

http://www.lryc.cn/news/15299.html

相关文章:

  • 第三届区块链服务网络(BSN)全球合作伙伴大会在杭州成功举办
  • 人工智能基础部分13-LSTM网络:预测上证指数走势
  • 内网穿透/组网/设备上云平台EasyNTS上云网关的安装操作指南
  • 易点天下基于 StarRocks 全面构建实时离线一体的湖仓方案
  • Tomcat的类加载机制
  • 【shell 编程大全】数组,逻辑判断以及循环
  • Android13 Bluetooth更新
  • 手工测试混了5年,年底接到了被裁员的消息....
  • Umi框架
  • 教你学git
  • 【工作笔记】syslog,kern.log大量写入invalid cookie错误信息问题
  • 【C++】多线程
  • 0202插入删除-算法第四版红黑树-红黑树-数据结构和算法(Java)
  • vue 生成二维码插件 vue-qr使用方法
  • 网络工程课(二)
  • Pytorch并行计算(三): 梯度累加
  • 蓝桥杯入门即劝退(十八)最小覆盖子串(滑动窗口解法)
  • Android一~
  • 一月券商金工精选
  • UML中常见的9种图
  • 使用SpringBoot实现无限级评论回复功能
  • Kafka 介绍和使用
  • [学习笔记]Rocket.Chat业务数据备份
  • 【ZOJ 1090】The Circumference of the Circle 题解(海伦公式+正弦定理推论)
  • 【go】slice原理
  • 【数据库】MySQL概念知识语法-基础篇(DQL),真的很详细,一篇文章你就会了
  • 博客界的至高神:属于自己的WordPress网站,你值得拥有!
  • 操作系统(day13)-- 虚拟内存;页面分配策略
  • SQL零基础入门学习(四)
  • 19岁就患老年痴呆!这些前兆别忽视!