K8s中gRpc通信负载均衡失效

news/2024/7/10 1:19:16 标签: 负载均衡, kubernetes, service_mesh, istio

上篇文章在做 整合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.niftyadmin.cn/n/86668.html

相关文章

提高情商 倾听能力

让 chatgpt推荐的 1. 心理学倾听教程 2. 表达 - 比喻 具象 ,有画面感 https://blog.csdn.net/fei33423/article/details/129131137 小说: 1.《呼啸山庄》(Wuthering Heights)by Emily Bronte (高级) 2.《了不起的盖茨比》(The…

华为OD机试 - 选座位(Python) | 机试题+算法思路+考点+代码解析 【2023】

选座位 题目 疫情期间需要大家保证一定的社交距离 公司组织开交流会议,座位有一排共N个座位 编号分别为[0...n-1] 要求员工一个接着一个进入会议室 并且还可以在任何时候离开会议室 每当一个员工进入时,需要坐到最大社交距离的座位 例如: 位置A与左右有员工落座的位置距离…

[蓝桥杯] 递归与递推习题训练

文章目录 一、递归实现指数型枚举 1、1 题目描述 1、2 题解关键思路与解答 二、递归实现排列型枚举 2、1 题目描述 2、2 题解关键思路与解答 三、递归实现组合型枚举 3、1 题目描述 3、2 题解关键思路与解答 四、带分数 4、1 题目描述 4、2 题解关键思路与解答 五、费解的开关…

mmdetection测试阶段

首先需要训练,训练会自动生成:latest.pth 权重文件 根据权重文件生成“.pkl”文件; 下面以faster_rcnn为例,–out是只生成的权重文件地址,result是生成的pkl文件名; python ./tools/test.py ./configs/…

Ardiuno-交通灯

LED交通灯实验实验器件:■ 红色LED灯:1 个■ 黄色LED灯:1 个■ 绿色LED灯:1 个■ 220欧电阻:3 个■ 面包板:1 个■ 多彩杜邦线:若干实验连线1.将3个发光二极管插入面包板,2.用杜邦线…

LeetCode_动态规划_困难_1326.灌溉花园的最少水龙头数目

目录1.题目2.思路3.代码实现(Java)1.题目 在 x 轴上有一个一维的花园。花园长度为 n,从点 0 开始,到点 n 结束。 花园里总共有 n 1 个水龙头,分别位于 [0, 1, …, n] 。 给你一个整数 n 和一个长度为 n 1 的整数数…

Linux 软件包安装

目录 通过源代码编译安装 通过RPM软件包安装 通过Yum软件仓库安装 配置本地Yum源 通过yum安装软件 通过Dnf软件仓库安装 Linux软件包安装有四种方式:源代码、RPM、Yum、Dnf安装四种方式 通过源代码编译安装 通过源代码编译安装可以根据需求定制软件&#xff…

一键恢复和重装系统的区别是什么

如果电脑出现系统故障问题的时候,我们的电脑系统还原和系统重装都是很好的解决方法之一,不过是二者之间是有区别的。那么我们的电脑系统还原和系统重装有什么区别呢?现在就跟大家聊聊电脑一键恢复和重装系统的区别有哪些。 工具/原料: 系统…