Kubernetes Service集群IP,这个内部是如何跨不同节点进行负载均衡的 [英] Kubernetes Service cluster IP, how is this internally load balanced across different nodes

查看:37
本文介绍了Kubernetes Service集群IP,这个内部是如何跨不同节点进行负载均衡的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个部署,导致 4 个 pod 存在于 2 个节点上.

I create a deployment which results in 4 pods existing across 2 nodes.

然后我通过一个服务公开这些 pod,从而产生以下集群 IP 和 pod 端点:

I then expose these pods via a service which results in the following cluster IP and pod endpoints:

Name:                     s-flask
......
IP:                       10.110.201.8
Port:                     <unset>  9080/TCP
TargetPort:               5000/TCP
NodePort:                 <unset>  30817/TCP
Endpoints:                
192.168.251.131:5000,192.168.251.132:5000,192.168.251.134:5000 + 1 more...

如果通过集群 IP 在内部访问服务,请求会在两个节点和所有 Pod 之间进行平衡,而不仅仅是单个节点上的 Pod(例如通过 nodePort 访问).

If accessing the service internally via the cluster IP, the requests are balanced across both nodes and all pods, not just the pods on a single node (e.g. like access via a nodePort).

我知道 kubernetes 使用 IP 表来平衡单个节点上跨 pod 的请求,但我找不到任何解释 kubernetes 如何跨多个节点平衡内部服务请求的文档(我们不使用负载平衡器或入口内部服务负载均衡).

I know kubernetes uses IP tables to balance requests across pods on a single node, but I can't find any documentation which explains how kubernetes balances internal service requests across multiple nodes (we are don't use load balancers or ingress for internal service load balancing).

集群 IP 本身是虚拟的,我认为这可以工作的唯一方法是,如果集群 IP 被循环映射到服务端点 IP 地址,客户端必须在其中查找集群 IP/服务并选择端点 IP?

The cluster IP itself is virtual, the only way I think this can work, is if the cluster IP is round robin mapped to a service endpoint IP address, where the client would have to look up the cluster IP / service and select an endpoint IP?

推荐答案

您需要的一切都在本文档的第二段虚拟 IP 和服务代理"中进行了说明:https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service

Everything you need is explained in second paragraph "Virtual IPs and service proxies" of this documentation: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service

简而言之:目前,根据代理模式,对于 ClusterIP,它只是循环/随机.它由 kube-proxy 完成,它运行在每个节点上,代理 UDP 和 TCP 并提供负载平衡.

In nutshell: currently, depending on the proxy mode, for ClusterIP it's just round robin/random. It's done by kube-proxy, which runs on each nodes, proxies UDP and TCP and provides load balancing.

最好将 kubernetes 视为一个整体而不是特定节点.抽象在这里发挥作用.

It's better to think of kubernetes as a whole rather than specific nodes. Abstraction does its thing here.

希望它能回答您的问题.

Hope it answers your question.

这篇关于Kubernetes Service集群IP,这个内部是如何跨不同节点进行负载均衡的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆