集群中的所有 Pod 都可以直接相互通信,而无需使用网络地址转换 (NAT)。即使是位于不同节点上的 Pod 也可以直接相互通信。
节点上的代理(例如系统守护程序或 kubelet)可以与该节点上的所有 Pod 通信。
因此,当网络托管两个集群时(如下图所示),一个问题是集群 1 中的 pod 如何与集群 2 中的 pod 通信?同样,集群外部的客户端或服务器(在图中标记为“其他客户端”和“其他服务器”)如何与集群内部的 pod 通信?
本文档介绍了平面模式网络模型和孤岛模式网络模型如何以不同方式解答这些问题。
平面模式网络模型
在完全集成或平面模式网络中,pod 在所有集群中具有唯一的 IP 地址。例如,集群 1 中的 Pod-A 具有的 IP 地址在集群 1 或集群 2 中的任何其他位置看不到。同样,集群 2 中的 Pod-G 在这两个集群中具有唯一的地址。这意味着,集群 1 中的 pod 可以直接与集群 2 中的任何 pod 通信(假设没有防火墙或其他阻止流量的政策)。pod 到 pod 的通信不需要网关或地址转换。
同样,集群外部的客户端和服务器可以通过 pod 的唯一 IP 地址直接与集群内部的 pod 进行通信,例如,在网络设备中静态配置路由或节点使用边界网关协议 (BGP) 通告它们可以处理给定 IP 范围的流量时。
因此,在平面网络中,通信非常简单直接:没有重叠的 IP 地址,并且您不需要使用叠加网络或 NAT。
孤岛模式网络模型
如果您拥有大型 IP 地址空间,并且有能力为每个 Pod 分配唯一的 IP 地址,则可以选择平面模式网络模型。但是,如果您无需使用大型 IP 地址空间,则孤岛模式网络模型是一个不错的选择。
在孤岛模式网络中,节点具有唯一的 IP 地址,但为了以经济实惠的方式使用稀缺的 IP 地址,pod 在集群中没有唯一的地址。这不会引起问题,因为一个集群中的 pod 绝不会直接与另一个集群中的 pod 通信。而是如下图所示,存在一些在一个集群中的 pod 与另一个集群中的 pod 之间进行协调的网关。
同样,从客户端进入集群的(入站)流量和离开集群的(出站)流量由类似的网关进行处理。网关可通过各种方式实现。例如,NAT、虚拟 IP 地址 (VIP) 和代理都是网关的一些示例。它们会执行 IP 地址转换,其作用是确保 Pod IP 的私密性。
在孤岛模式网络模型中,可以在每个集群中使用相同的 Pod IP 地址。也就是说,Pod IP 地址在集群中不必是唯一的。如下图所示,您可以在每个集群中使用相同的 Pod IP 地址,因为一个集群中的 Pod 绝不会直接与另一个集群中的 Pod 通信。
孤岛模式网络模型的主要优势是能够以这种方式重复使用 Pod IP 地址。
这两种模型的优缺点
下面列出了这两种模型的一些优缺点:
平面网络比孤岛网络更快,因为孤岛模式下的网关执行地址转换,这些转换会产生性能费用。
在平面网络中调试集群问题更加容易,因为该网络中的所有内容都具有唯一的 IP 地址,因此可以更轻松地查明问题发生的位置。例如,pod IP 未掩藏在节点的 IP 地址后面,因此可以更轻松地准确确定导致问题的 pod。同样,在平面模式中,客户端 IP 不会以在孤岛模式中所采用的方式进行遮盖,这也有助于调试。
如果 IP 地址稀缺,或者 IP 空间碎片化(即没有大型 IP 地址块),则您可能无法使用平面网络模型。在这种情况下,孤岛网络是更好的选择。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-01。"],[],[],null,["Kubernetes doesn't guarantee that anything outside a cluster can communicate\nwith the cluster and only promises to provide the following functionality:\n\n- All pods in a cluster can communicate directly with each other\n without having to resort to Network Address Translation (NAT). Even pods that\n are on different nodes can communicate directly with each other.\n\n- Agents on a node, such as system daemons or a kubelet, can communicate with\n all pods on that node.\n\nThus when a network is hosting two clusters, as pictured below, a question to\nask is how do pods in cluster 1 communicate with pods in cluster 2? Similarly,\nhow do clients or servers outside the clusters, marked as \"Other client\" and\n\"Other server\" in the diagram, communicate with a pod inside a cluster?\n\nThis document explains how a *flat-mode* network model and an *island-mode*\nnetwork model answer these questions differently.\n\nFlat mode network model\n\nIn a fully-integrated or flat-mode network, pods have unique IP addresses across\nall the clusters. For example, `Pod-A` in cluster 1 has an IP address that you\nwon't see anywhere else in cluster 1 or cluster 2. Similarly, `Pod-G` in cluster\n2 has a unique address across both clusters. This means that pods from cluster 1\ncan communicate directly with any of the pods in cluster 2 (assuming there are\nno firewalls or other policies that would block traffic). No gateway or address\ntranslation is needed for pod to pod communication.\n\nSimilarly, clients and servers outside a cluster can directly communicate with a\npod inside a cluster via the pod's unique IP address if, for instance,\nrouting is configured statically in network devices or [Border Gateway Protocol (BGP)](https://en.wikipedia.org/wiki/Border_Gateway_Protocol)\nis used by the nodes to advertise that they can handle traffic for a given\nIP range.\n\nThus, in flat networks, communication is easy and direct: there are no\noverlapping IP addresses, and you don't need to use overlay networks or NAT.\n\nIsland mode network model\n\nA flat-mode network model is an option if you have the luxury of a large IP\naddress space, and you can afford to assign a unique IP address to each pod.\nHowever, if a large IP address space isn't an option for you, an island-mode\nnetwork model is a good choice.\n\nIn an island-mode network, nodes have unique IP addresses but, in order to be\neconomical with scarce IP addresses, pods don't have unique addresses across\nclusters. This doesn't cause problems because pods in one cluster never directly\ncommunicate with pods in another cluster. Instead, as the following diagram\nshows, there are gateways that mediate between a pod in one cluster and a pod\nin another cluster.\n\nSimilarly, (ingress) traffic from a client that's coming into a cluster and\n(egress) traffic leaving a cluster are handled by similar gateways. Gateways\ncan be implemented in various ways. For example, NAT, Virtual IP addresses\n(VIPs), and proxies are some examples of gateways. They perform IP address\ntranslations which have the effect of keeping pod IPs private.\n\nIn the island-mode network model, the same pod IP addresses can be used in each\ncluster. That is, the pod IP addresses don't have to be unique across clusters.\nAs the following diagram suggests, you can use the same pod IP addresses in each\ncluster because a pod in one cluster never communicates directly to a pod in\nanother cluster.\n\nA major advantage of the island-mode network model is that pod IP addresses can be\nre-used in this fashion.\n\nAdvantages and disadvantages of the two models\n\nSome of the advantages and disadvantages of the two models are listed here:\n\n- A flat network is faster than an island network because gateways in island\n mode perform address translations, and these translations incur a\n performance cost.\n\n- Debugging cluster problems is easier in flat networks because everything in\n the network has a unique IP address and so it's easier to pinpoint where a\n problem occurs. For instance, pod IPs aren't masked behind a node's IP address\n and so it's easier to determine exactly which pod is causing problems.\n Similarly, client IPs aren't obscured in flat mode the way they are in island\n mode and that also helps with debugging.\n\n- You may not be able to use the flat network model if you have scarce IP\n addresses or if your IP space is fragmented (that is, if you don't have large\n chunks of IP addresses). In that case an island network is a better option.\n\nIt's important to note that flat and island network models are just two of the\npossible network models, and there are lots of variations even within these\nmodels."]]