- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我见过这样的场景:来自一个工作负载的请求发送到另一个工作负载的 ClusterIP 服务,但没有设置相关性,只会被路由到关联 pod 的子集。此服务的 Endpoints 对象确实显示了所有 pod IP。
我做了一个小实验来弄清楚发生了什么。
实验
我将 minikube 设置为具有 3 个副本的“路由器”工作负载,将请求发送到同样具有 3 个 pod 的“后端”工作负载。路由器只是向服务名称发送请求,如 http://backend
.
我通过 http://$MINIKUBE_IP:$NODE_PORT
向路由器服务发送了 100 个请求,因为它暴露为 NodePort
服务。然后我观察了哪些后端 pod 实际处理了请求。我多次重复这个测试。
在大多数情况下,只有 2 个后端 pod 处理任何请求,偶尔会出现所有 3 个都处理的情况。在这些实验中,我没有看到所有请求都发送到一个的地方,尽管我在 AKS 中运行其他测试之前已经看到它发生了。
这使我得出这样的理论,即路由器与其连接的后端 Pod 保持持久连接。鉴于有 3 个路由器和 3 个后端,所有 3 个路由器“坚持”到一个后端的可能性为 11%,在 3 个路由器之间,它们坚持到其中的 2 个后端的可能性为 67%,每个路由器有 22% 的可能性路由器坚持不同的后端 pod(1 对 1)。
这是路由器到后端连接的一种可能组合(共 27 种):
禁用 HTTP Keep-Alive
如果我使用 Transport
在路由器的 http 客户端中禁用 HTTP Keep-Alives,然后我向路由器发出的任何请求都会根据需要在每次测试运行时均匀分布在不同的后端之间。
client := http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
},
}
resp, err := client.Get("http://backend")
所以这个理论似乎是准确的。但这是我的问题:
kube-proxy
在中间,所以我希望路由器 pod 和 kube-proxy
之间有任何持久连接。以及在kube-proxy
之间和后端 pod 。 最佳答案
此 excellent article详细介绍了您的问题。
Kubernetes 服务确实不会对长期 TCP 连接进行负载平衡。
在后台服务(在大多数情况下)使用 iptables
分发 Pod 之间的连接。但是iptables
它不是设计为平衡器,而是防火墙。它无法进行高级负载平衡。
作为弱替代iptables
可以以一定的概率创建(或不创建)与某个目标的连接 - 因此可以用作 L3/L4 平衡器。这个机制是什么kube-proxy
使用有点模仿负载平衡。
Does iptables use round-robin?
No,
iptables
is primarily used for firewalls, and it is not designed to do load balancing.
However, you could craft a smart set of rules that could makeiptables
behave like a load balancer.
And this is precisely what happens in Kubernetes.If you have three Pods,
kube-proxy
writes the following rules:
- select Pod 1 as the destination with a likelihood of 33%. Otherwise, move to the next rule
- choose Pod 2 as the destination with a probability of 50%. Otherwise, move to the following rule
- select Pod 3 as the destination (no probability)
What happens when you use keep-alive with a Kubernetes Service?
Let's imagine that front-end and backend support keep-alive.
You have a single instance of the front-end and three replicas for the backend.
The front-end makes the first request to the backend and opens the TCP connection.
The request reaches the Service, and one of the Pod is selected as the destination.
The backend Pod replies and the front-end receives the response.
But instead of closing the TCP connection, it is kept open for subsequent HTTP requests.
What happens when the front-end issues more requests?
They are sent to the same Pod.Isn't iptables supposed to distribute the traffic?
It is.
There is a single TCP connection open, and iptables rule were invocated the first time.
One of the three Pods was selected as the destination.
Since all subsequent requests are channelled through the same TCP connection,iptables
isn't invoked anymore.
kube-proxy
本身不管理任何流量。
iptables
谁实际聆听、分发、执行 DNAT 等。
关于kubernetes - kube-proxy 如何处理 Pod 之间到 Service 的持久连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65224181/
kubernetes的新手,希望了解使用不同kubernetes对象的最佳实践,并且很难理解“Pods”和“Static Pods”在功能上的主要区别(如果有)吗? 主要问题如下: 问题1:如果有功能
以下是 pods 文件的截图,其中不包含 AFNetworking 库。当我在终端中运行命令 pod install 时,它安装了 AFNetworking 库版本 3.0.1。我无法理解为什么会这样
在通过 pod lib create projectName 创建的目录中执行 pod init 是否受支持?它似乎对我不起作用,但否则如何指定他们正在创建的 pod 的上游依赖项? pod inst
我正在尝试制作一个 Pod::Simple::HTML 的简单子(monad)类用于 Pod::Simple::HTMLBatch .我希望使用 POD::Weaver 对所有 POD 进行预处理.但
根据定义here , POD 是一个简单的类,没有用户定义的构造函数、非静态成员,并且只包含简单的数据类型。 问题是,下面这两个类是否等同于 POD 类型(就内存占用而言): class pod {
使用 Airflow 在 AWS EKS 上运行 KubernetesPodOperator 获取 kubernetes.client.rest.ApiException: (400),指出版本\"v
据我了解,当 POD 与服务对话时,IP 表已由 CNI 提供商更新(这可能特定于某些但不是所有 CNI 提供商)。 iptables 基本上提供了一个虚拟 IP,然后循环或分发(以某种方式)到后端临
我有一个 pod 需要将数据持久保存到 pod 外部的位置。我认为persistentVolume 是一个好主意。名为 writerPod 的 pod 需要对该卷进行读写访问。 多个其他 Pod(我称
我想知道,如果 HPA 考虑一个 pod 中多个容器的 CPU 利用率的平均值,以便向上/向下扩展数量。 pod 。例如,如果我为具有 2 个容器的部署(pod)指定如下所示的 HPA。为了让 HPA
我有以下情况: 我有几个微服务,现在只有两个是相关的。 - Web 套接字服务 API - 调度服务 我们有 3 个用户,我们将分别称为 1、2 和 3。这些用户将自己连接到我们后端的 Web 套接字
我已经注意到,当使用kubectl时,您几乎可以互换使用 pod 和 pods 。是否有任何实例可以使用一个实例而不是另一个实例来获得不同的结果,或者您可以只使用其中一个而不用担心呢? 例如: kub
我尝试使用命令 pod update 更新我的 podfile但它需要永远。 我也按照这个问题做了所有的步骤 cocoapods - 'pod install' takes forever但什么都没有
我正在设置一个 Kubernetes 主节点。 只是主节点,暂时没有工作节点。 使用 this tutorial. 完成设置,没有任何问题现在, $kubectl get pods -o wide -
是否可以在 pod install 期间让一个 Pod 保持不变和pod update ? pod update 不是一个选项。 最佳答案 您实际上可以使用pod update [NAMES...]来
基本上,我有一个部署,它创建了 3 个自动扩展的容器:PHP-FPM、NGINX 和包含应用程序的容器,所有这些都设置了 secret 、服务和入口。该应用程序还在 PHP-FPM 和 NGINX 之
在为Kubernetes创建/添加节点时,我们还必须创建Canal pod。 当前,kubernetes在尝试调度Pod之前不会等待Canal Pod准备就绪,从而导致失败(错误如下) Error s
我正在寻找一个选项来从部署/复制中删除 pod 而不删除它。我找到了一个很好的解决方案 using selector and labels here ,但在我的情况下这是不可能的,因为我不是 pod/
来自 PodInterface两个操作Delete和 Evict似乎具有相同的效果:删除旧 Pod 并创建一个新 Pod。 如果两个操作效果一样,为什么删除一个Pod并创建一个新的Pod需要两个API
Kubernetes版本1.12.3。 kubectl排水是先移开 pods 还是先创建 pods 。 最佳答案 您可以在节点上执行维护(例如内核升级,硬件维护等)之前,使用kubectlrain安全
有没有办法通过主机名访问 pod? 我有一个主机名:my-pod-1需要使用主机名连接到另一个 pod:my-pod-2 . 在没有服务的情况下实现这一目标的最佳方法是什么? 最佳答案 通过您的描述,
我是一名优秀的程序员,十分优秀!