<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>OPSaid – Cilium</title><link>https://opsaid.net/docs/cloud-native/networking/cilium/</link><description>Recent content in Cilium on OPSaid</description><generator>Hugo -- gohugo.io</generator><atom:link href="https://opsaid.net/docs/cloud-native/networking/cilium/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: Overview</title><link>https://opsaid.net/docs/cloud-native/networking/cilium/overview/</link><pubDate>Mon, 08 Jan 2024 09:52:32 +0800</pubDate><guid>https://opsaid.net/docs/cloud-native/networking/cilium/overview/</guid><description>
&lt;h2 id="简要概述">简要概述&lt;/h2>
&lt;p>Cilium 的基础是一种名为 eBPF 的新 Linux 内核技术，它使得在 Linux 内核内部动态插入强大的安全可见性和控制逻辑成为可能。由于 eBPF 运行在 Linux 内核内部，因此可以在不修改应用程序代码或容器配置的情况下应用和更新 Cilium 安全策略。&lt;/p>
&lt;p>Hubble 是一个完全分布式的网络和安全可观察性平台，它构建在 Cilium 和 eBPF 之上，以实现对服务通信和行为以及网络基础设施的深度可见性，完全透明地实现这一目标。&lt;/p>
&lt;p>通过构建在 Cilium 之上，Hubble 可以利用 eBPF 来实现可见性。通过依赖 eBPF，所有的可见性都是可编程的，这使得可以采用一种动态的方法，最小化开销同时提供用户所需的深度和详细的可见性。Hubble 已经被创建并专门设计，以充分发挥这些新的 eBPF 功能。&lt;/p>
&lt;h3 id="主要特性成熟度">主要特性成熟度&lt;/h3>
&lt;ul>
&lt;li>eBPF Networking&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>功能&lt;/th>
&lt;th>状态&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Kubernetes CNI&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Load Balancing&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Network Policy&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Kube-proxy Replacement&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Egress Gateway&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Transparent Encryption (IPSec and WireGuard)&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Bandwidth Manager&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;ul>
&lt;li>Cilium Mesh&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>功能&lt;/th>
&lt;th>状态&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Multi-Cluster (ClusterMesh)&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>External Workloads&lt;/td>
&lt;td>Beta&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;ul>
&lt;li>Hubble Observability&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>功能&lt;/th>
&lt;th>状态&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Hubble CLI&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Service Map &amp;amp; Hubble UI&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Prometheus metrics&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;ul>
&lt;li>Cilium Service Mesh&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>功能&lt;/th>
&lt;th>状态&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Kubernetes Ingress Support&lt;/td>
&lt;td>稳定&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Gateway API Support&lt;/td>
&lt;td>Beta&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>L7-Aware Traffic Management&lt;/td>
&lt;td>Beta&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Mutual Authentication (Beta)&lt;/td>
&lt;td>Beta&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>SPIFFE integration&lt;/td>
&lt;td>Beta&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>详见 &lt;a href="https://docs.cilium.io/en/stable/community/roadmap/#major-feature-status">cilium roadmap&lt;/a>。&lt;/p>
&lt;h3 id="为什么需要它">为什么需要它&lt;/h3>
&lt;p>Cilium 通过 eBPF（Extended Berkeley Packet Filter）技术使得以前无法实现的对系统和应用程序进行细粒度和高效的可见性和控制成为可能。&lt;/p>
&lt;p>它在完全透明的情况下实现这一点，无需对应用程序进行任何更改。eBPF 同样适用于处理现代容器化工作负载以及更传统的工作负载，如虚拟机和标准的Linux进程。&lt;/p>
&lt;p>在面向高度动态的微服务的转变中，连接微服务之间的安全性既是挑战也是机遇。传统的Linux网络安全方法（例如，iptables）基于IP地址和TCP/UDP端口进行过滤，但在动态微服务环境中，IP地址经常变动。容器的高度不稳定的生命周期导致这些方法难以与应用程序一起进行横向扩展，因为负载均衡表和携带数十万规则的访问控制列表需要以不断增长的频率进行更新。协议端口（例如，用于HTTP流量的TCP端口80）不再能够用于安全目的来区分应用程序流量，因为该端口用于跨服务的广泛消息范围。&lt;/p>
&lt;h2 id="存在哪些功能">存在哪些功能&lt;/h2>
&lt;h3 id="透明地保护应用">透明地保护应用&lt;/h3>
&lt;p>相比传统防火墙保护在第3、4层协议，要求在特定端口上运行的协议要么完全受信任，要么被完全阻止，而 cilium 可同时具备保护应用层协议的能力，如 HTTP、gRPC、Kafka，提供了过滤单个应用程序协议请求的能力，例如：&lt;/p>
&lt;ol>
&lt;li>允许所有使用 GET 方法且路径为 /public/.* 的 HTTP 请求，拒绝所有其他请求；&lt;/li>
&lt;li>允许 service1 在 Kafka 主题 topic1 上生成，允许 service2 在 topic1 上消费，拒绝所有其他 Kafka 消息；&lt;/li>
&lt;li>要求所有 REST 调用中必须存在 HTTP 头 X-Token: [0-9]+。&lt;/li>
&lt;/ol>
&lt;p>其他参考官方&lt;a href="https://docs.cilium.io/en/stable/security/policy/language/#layer-7-examples">示例&lt;/a>。&lt;/p>
&lt;h3 id="基于身份进行安全的服务间通信">基于身份进行安全的服务间通信&lt;/h3>
&lt;p>现代分布式应用程序依赖于诸如应用容器等技术，以促进在部署时的灵活性和按需的扩展。这导致在短时间内启动大量应用容器。典型的容器防火墙通过过滤源IP地址和目标端口来保护工作负载。这一概念要求在集群中的任何地方启动容器时，所有服务器上的防火墙都要进行操作。&lt;/p>
&lt;p>为了避免这种限制规模的情况，Cilium为共享相同安全策略的应用容器组分配了安全身份。然后，该身份与应用容器发出的所有网络数据包关联，允许在接收节点验证身份。安全身份管理是通过键值存储来执行的。&lt;/p>
&lt;h3 id="安全访问和从外部服务中获取数据">安全访问和从外部服务中获取数据&lt;/h3>
&lt;p>基于标签的安全性是集群内部访问控制的首选工具。&lt;/p>
&lt;p>为了保护对外部服务的访问，传统的 CIDR 基于的安全策略在入口和出口方向都得到支持。这允许限制对应用容器的访问，以及从特定IP范围进行访问。&lt;/p>
&lt;h3 id="简单的组网">简单的组网&lt;/h3>
&lt;p>简单的扁平3层网络，具有跨多个集群的能力，连接了所有应用容器。&lt;/p>
&lt;p>通过使用主机范围分配器，IP分配保持简单。这意味着每个主机都可以在主机之间无需协调地分配IP地址。&lt;/p>
&lt;p>多节点支持以下网络模型：&lt;/p>
&lt;ul>
&lt;li>Overlay&lt;/li>
&lt;/ul>
&lt;p>基于封装的虚拟网络，覆盖所有主机。目前内置支持 VXLAN 和 Geneve，但所有 Linux 支持的封装格式都可以启用。&lt;/p>
&lt;p>何时使用这种模式：这种模式具有最小的基础设施和集成要求。它在几乎任何网络基础设施上都可以工作，因为唯一的要求是主机之间通常已经存在IP连接。&lt;/p>
&lt;ul>
&lt;li>Native Routing&lt;/li>
&lt;/ul>
&lt;p>本地路由，使用 Linux 主机的常规路由表，网络需要能够路由应用容器的IP地址。&lt;/p>
&lt;p>何时使用这种模式：这种模式适用于高级用户，并需要对底层网络基础设施有一定的了解。这种模式与以下情况配合良好：&lt;/p>
&lt;ol>
&lt;li>本地IPv6网络&lt;/li>
&lt;li>与云网络路由器一起使用&lt;/li>
&lt;li>如果已经在运行路由守护程序&lt;/li>
&lt;/ol>
&lt;h3 id="负载均衡">负载均衡&lt;/h3>
&lt;p>可完全替代 kube-proxy 组件，支持应用容器之间以及与外部服务之间的负载均衡，它是通过使用高效的哈希表在 eBPF 中实现的，允许几乎无限的扩展。&lt;/p>
&lt;p>对于南北向负载均衡（集群内流量），Cilium 的 eBPF 实现被优化以实现最大性能，可以附加到 XDP（eXpress Data Path），并且当不在源主机上执行负载均衡操作时，可支持直接由该服务器返回（DSR）以及 Maglev 一致性哈希。&lt;/p>
&lt;p>对于东西向负载均衡（集群外流量），Cilium 在Linux 内核的套接字层（例如在TCP连接时）执行高效的服务到后端的转换，从而避免在更低层中执行每数据包 NAT 操作的开销。&lt;/p>
&lt;h3 id="带宽管理">带宽管理&lt;/h3>
&lt;p>通过使用 eBPF 实现高效的 EDT（Earliest Departure Time）用于速率限制，对从节点出口的容器流量进行带宽管理。&lt;/p>
&lt;p>与传统方法，如在带宽 CNI 插件中使用的 HTB（Hierarchy Token Bucket）或 TBF（Token Bucket Filter）相比，可以显著降低应用程序的传输延迟，并避免在多队列网卡下出现锁定问题。&lt;/p>
&lt;h3 id="监控和故障排查">监控和故障排查&lt;/h3>
&lt;p>提供原生可观测性数据，这对于运行在集群上的分布式应用故障时，对排障定位至关重要。&lt;/p>
&lt;p>包括以下技术要点：&lt;/p>
&lt;ol>
&lt;li>事件监控与元数据&lt;/li>
&lt;/ol>
&lt;p>当数据包被丢弃时，工具不仅报告数据包的源和目标IP，还提供发送方和接收方的完整标签信息等信息。&lt;/p>
&lt;ol start="2">
&lt;li>通过 Prometheus 导出指标&lt;/li>
&lt;/ol>
&lt;p>关键指标通过 Prometheus 标准导出，以与现有的仪表板集成。&lt;/p>
&lt;ol start="3">
&lt;li>Hubble&lt;/li>
&lt;/ol>
&lt;p>专为 Cilium 编写的可观察性平台，它提供服务依赖图、操作监控和警报、基于流日志的应用程序和安全可见性。&lt;/p>
&lt;h2 id="包含哪些组件">包含哪些组件&lt;/h2>
&lt;h3 id="cilium-agent">cilium-agent&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>cilium-agent
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>以 &amp;ldquo;DaemonSet&amp;rdquo; 资源名 &amp;ldquo;cilium&amp;rdquo; 在集群中的每个节点上运行：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>/usr/bin/cilium-agent --config-dir=/tmp/cilium/config-map
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>监听来自 Kubernetes 的事件，以了解容器或工作负载何时启动和停止，它管理 eBPF 程序，这些程序由 Linux 内核用于控制这些容器的所有网络访问。&lt;/p>
&lt;h3 id="cilium-cli">cilium cli&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>cilium
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>客户端工具 &lt;code>cilium&lt;/code> 是与运行在同一节点上的 &lt;code>cilium-agent&lt;/code> 进行交互，命令行界面允许检查本地代理的状态，它还提供工具来直接访问 eBPF 映射以验证其状态。&lt;/p>
&lt;p>注意在 &lt;code>cilium-agent&lt;/code> 容器内也存在一个命名为 &lt;code>cilium&lt;/code> 的二进制文件，二者不要混淆。&lt;/p>
&lt;h3 id="cilium-operator">cilium-operator&lt;/h3>
&lt;p>负责管理在集群中一次性处理的任务，而不是在集群中的每个节点上都进行处理，它不转发任何网络数据包，如果暂时不可用，集群仍然会正常运行。&lt;/p>
&lt;p>根据不通的配置，服务不可用时，以下操作可能会失败：&lt;/p>
&lt;ol>
&lt;li>IP 地址管理（IPAM）不可用，可能导致新工作负载的调度延迟，尤其是 Pod 需要分配新的 IP 地址；&lt;/li>
&lt;li>无法更新 kvstore 心跳键可能导致代理宣告 kvstore 不健康并重新启动。&lt;/li>
&lt;/ol>
&lt;h3 id="cni-plugin">CNI Plugin&lt;/h3>
&lt;p>当 Pod 被调度或从宿主上移除时，&lt;code>cilium-cni&lt;/code> 将会被 k8s 启动，它跟 cilium api 交互，以便更新网络、负载均衡、安全策略等。&lt;/p>
&lt;h3 id="hubble-server">hubble server&lt;/h3>
&lt;p>Hubble 服务端已内嵌到 &lt;a href="https://opsaid.net/docs/cloud-native/networking/cilium/overview/#cilium-agent">cilium-agent&lt;/a> 以实现高性能和低开销，它对 eBPF 提供可见性，并提供了 gRPC 服务用于检索数据流跟 Prometheus 标准的性能数据，相关配置如下：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># An additional address for Hubble server to listen to (e.g. &amp;#34;:4244&amp;#34;).&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">hubble-listen-address&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;:4244&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">hubble-disable-tls&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic">#hubble-tls-cert-file: /var/lib/cilium/tls/hubble/server.crt&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic">#hubble-tls-key-file: /var/lib/cilium/tls/hubble/server.key&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic">#hubble-tls-client-ca-files: /var/lib/cilium/tls/hubble/client-ca.crt&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="hubble-relay">hubble-relay&lt;/h3>
&lt;p>hubble-relay 是一个独立的组件，它知道所有运行中的 hubble 服务器，并通过连接到它们各自的 gRPC API 并提供代表集群中所有服务器的API，提供了集群范围的可见性。&lt;/p>
&lt;h3 id="hubble-cli">hubble cli&lt;/h3>
&lt;p>Hubble CLI（hubble）是一个命令行工具，能够连接到hubble-relay的gRPC API或本地服务器以检索流事件。&lt;/p>
&lt;h3 id="hubble-ui">hubble-ui&lt;/h3>
&lt;p>图形用户界面（hubble-ui）利用基于 relay 的可见性，提供了图形化的服务依赖和连接图。&lt;/p>
&lt;h3 id="ebpf">eBPF&lt;/h3>
&lt;p>eBPF 是一个最初引入用于过滤网络数据包的 Linux 内核字节码解释器，例如用于 tcpdump 和套接字过滤。&lt;/p>
&lt;p>后来，它通过添加额外的数据结构，如哈希表和数组，以及支持数据包篡改、转发、封装等的附加操作而得到扩展。&lt;/p>
&lt;p>内核中的验证器确保 eBPF 程序在运行时是安全的，并且即时编译器将字节码转换为特定CPU架构的指令，以实现本机执行效率。&lt;/p>
&lt;p>eBPF 程序可以在内核的各种挂钩点上运行，例如用于处理传入和传出的数据包。&lt;/p>
&lt;h3 id="kubernetes-crd">Kubernetes CRD&lt;/h3>
&lt;p>在 cilium 也需要持久化保存一些状态数据，默认是通过 k8s crd 实现，有以下类型：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>ciliumcidrgroups.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumclusterwidenetworkpolicies.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumendpoints.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumexternalworkloads.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumidentities.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliuml2announcementpolicies.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumloadbalancerippools.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumnetworkpolicies.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumnodeconfigs.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumnodes.cilium.io
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ciliumpodippools.cilium.io
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="key-value-store">Key-Value Store&lt;/h3>
&lt;p>在 cilium 默认持久化状态是通过使用 Kubernetes CRD 来实现。&lt;/p>
&lt;p>作为一种优化，可以选择使用键值存储来提高集群的可伸缩性，因为直接使用键值存储可以更高效地处理变更通知和存储需求。&lt;/p>
&lt;p>当前仅支持 &lt;a href="https://github.com/etcd-io/etcd">etcd&lt;/a>。&lt;/p>
&lt;h2 id="关键术语">关键术语&lt;/h2>
&lt;h3 id="label">Label&lt;/h3>
&lt;p>标签是由键和值组成的一对字符串。&lt;/p>
&lt;p>标签可以格式化为一个带有 &amp;ldquo;key=value&amp;rdquo; 格式的字符串，键部分是必需且唯一的，一般使用反向域名的概念来实现，例如：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>io.cilium.mykey=myvalue
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>值部分是可选的，可以省略，例如：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>io.cilium.mykey
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>键名通常应由字符集 &amp;ldquo;[a-z0-9-.]&amp;rdquo; 组成，在使用标签选择资源时，键和值都必须匹配，例如当一个策略应用于所有带有标签 my.corp.foo 的端点时，标签 my.corp.foo=bar 将不匹配选择器。&lt;/p>
&lt;h3 id="label-source">Label Source&lt;/h3>
&lt;p>标签可以从各种来源派生。&lt;/p>
&lt;p>例如，一个端点将通过本地容器运行时派生与容器关联的标签，以及由 Kubernetes 提供的与 Pod 关联的标签。&lt;/p>
&lt;p>由于这两个标签命名空间不知道对方的存在，这可能导致标签键的冲突。&lt;/p>
&lt;p>为解决这种潜在的冲突，cilium 在导入标签时给所有标签键添加了前缀 &amp;ldquo;source:&amp;rdquo; 以指示标签的来源，例如&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>k8s:app.kubernetes.io/name=metrics-server
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=kube-system
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>k8s:io.cilium.k8s.policy.cluster=fake
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>k8s:io.cilium.k8s.policy.serviceaccount=metrics-server
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>k8s:io.kubernetes.pod.namespace=kube-system
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>reserved:health
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>为每个标签来源固定分配唯一的名称，目前支持以下：&lt;/p>
&lt;ol>
&lt;li>&amp;ldquo;container&amp;rdquo;: 用于从本地容器运行时派生的标签；&lt;/li>
&lt;li>&amp;ldquo;k8s&amp;rdquo;: 用于从 Kubernetes 派生的标签；&lt;/li>
&lt;li>&amp;ldquo;reserved&amp;rdquo;: 用于特殊保留标签，见以下特殊标识表；&lt;/li>
&lt;li>&amp;ldquo;unspec&amp;rdquo;: 用于未指定来源的标签；&lt;/li>
&lt;li>&amp;ldquo;any&amp;rdquo;: 表示匹配所有标签，不考虑以上来源。&lt;/li>
&lt;/ol>
&lt;p>当使用标签标识其他资源时，可以包含源以限制标签匹配到特定类型。&lt;/p>
&lt;p>如果未提供源，则标签源默认为 any:，这将匹配所有标签，如果提供了源，则选择和匹配标签的源需要匹配。&lt;/p>
&lt;p>特殊标识：&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>编号&lt;/th>
&lt;th>标识&lt;/th>
&lt;th>描述&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>0&lt;/td>
&lt;td>reserved:unknown&lt;/td>
&lt;td>x&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1&lt;/td>
&lt;td>reserved:host&lt;/td>
&lt;td>本地主机。任何源自或指定给本地主机IP的流量&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2&lt;/td>
&lt;td>reserved:world&lt;/td>
&lt;td>集群外的任何网络端点&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>3&lt;/td>
&lt;td>reserved:unmanaged&lt;/td>
&lt;td>未由Cilium管理的端点，例如在安装Cilium之前启动的Kubernetes Pod&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>4&lt;/td>
&lt;td>reserved:health&lt;/td>
&lt;td>由 cilium-agent 生成的ip, 用于健康检查&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>5&lt;/td>
&lt;td>reserved:init&lt;/td>
&lt;td>尚未解析身份的端点被分配init身份。表示端点处于某种阶段&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>6&lt;/td>
&lt;td>reserved:remote-node&lt;/td>
&lt;td>集群排除本节点，其他远程主机集合&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>7&lt;/td>
&lt;td>reserved:kube-apiserver&lt;/td>
&lt;td>运行 kube-apiserver 后端服务的节点&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>8&lt;/td>
&lt;td>reserved:ingress&lt;/td>
&lt;td>用作 ingress 代理连接的源地址的IP&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="endpoint">Endpoint&lt;/h3>
&lt;p>Cilium 为容器分配 IP 地址，而同一个 Pod 内多个容器共享同一个地址，他们则称为一个端点（Endpoint），如：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>$ kubectl get ciliumendpoints.cilium.io -n kube-system
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>NAME ENDPOINT ID IDENTITY ID INGRESS ENFORCEMENT EGRESS ENFORCEMENT VISIBILITY POLICY ENDPOINT STATE IPV4 IPV6
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>hubble-relay-69dc7ffc7c-nbd94 &lt;span style="color:#0000cf;font-weight:bold">1339&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">46722&lt;/span> &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; ready 192.168.201.6
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>hubble-ui-56969ff7db-4kkbx &lt;span style="color:#0000cf;font-weight:bold">646&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">10752&lt;/span> &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; ready 192.168.201.4
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>metrics-server-844d95488f-8whf6 &lt;span style="color:#0000cf;font-weight:bold">1464&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">14083&lt;/span> &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; ready 192.168.201.35
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>metrics-server-844d95488f-9ctrp &lt;span style="color:#0000cf;font-weight:bold">1083&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">59399&lt;/span> &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; ready 192.168.201.14
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>metrics-server-844d95488f-mcjkl &lt;span style="color:#0000cf;font-weight:bold">6&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">59399&lt;/span> &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; &amp;lt;status disabled&amp;gt; ready 192.168.201.24
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>分配独立的 IP 地址使得每个端点可以使用独立的网络协议栈，默认行为是为每个端点分配 IPv4 和 IPv6 地址，可以通过配置单独开启或关闭。&lt;/p>
&lt;p>同时为了标识目的，cilium 为每个集群节点上的所有端点分配一个内部端点ID，且 ID 在单个集群节点的上下文中是唯一的。&lt;/p>
&lt;p>端点会自动从与其关联的容器拉取标签作为元数据，然后使用这些元数据来标识端点，以用于安全策略、负载均衡和路由等目的。这些元数据的来源取决于正在使用的编排系统，目前支持以下元数据检索机制：&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>编排系统&lt;/th>
&lt;th>获取方式&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Kubernetes&lt;/td>
&lt;td>Pod labels (via k8s API)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Docker&lt;/td>
&lt;td>Container labels (via Docker API)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="identity">Identity&lt;/h3>
&lt;p>所有端点（Endpoint）都被分配一个身份（Identity），用于强制执行端点之间的基本连接。在传统的网络术语中，这相当于第3层的强制执行。&lt;/p>
&lt;p>身份通过标签进行识别，并被赋予一个在整个集群中唯一的标识符。端点被分配与其安全相关标签匹配的身份，即所有共享相同安全相关标签集的端点将共享相同的身份。这个概念允许将策略执行扩展到大量的端点，因为许多个体端点通常会共享与应用程序扩展相同的安全标签集。&lt;/p>
&lt;p>端点的身份是根据派生到端点的Pod或容器的标签来推导的。当启动Pod或容器时，Cilium将根据容器运行时接收到的事件创建一个端点，以在网络上表示Pod或容器。然后，Cilium将解析创建的端点的身份。每当Pod或容器的标签发生变化时，身份将被重新确认，并根据需要自动修改。&lt;/p>
&lt;p>与容器或 Pod 相关联的并非所有标签在推导身份时都是有意义的。标签可能用于存储元数据，例如容器启动的时间戳。Cilium 需要知道哪些标签是有意义的，并在推导身份时将其考虑在内。为此，用户需要指定一个有意义的标签字符串前缀列表。标准行为是包括所有以 id. 前缀开头的标签，例如 id.service1、id.service2、id.groupA.service44。在启动代理时可以指定有意义的标签前缀列表。&lt;/p>
&lt;p>TODO;&lt;/p>
&lt;h3 id="node">Node&lt;/h3>
&lt;p>Cilium 将节点称为集群的一个个体成员，每个节点必须运行 &lt;code>cilium-agent&lt;/code>，并且将以大多数自治的方式运行。为了简化和提高可伸缩性，不同节点上运行的 cilium-agent 之间的状态同步被保持到最小。它仅通过键值存储或数据包元数据进行。&lt;/p></description></item><item><title>Docs: kube-proxy</title><link>https://opsaid.net/docs/cloud-native/networking/cilium/kube-proxy/</link><pubDate>Fri, 12 Apr 2024 10:52:11 +0800</pubDate><guid>https://opsaid.net/docs/cloud-native/networking/cilium/kube-proxy/</guid><description>
&lt;h2 id="简要概述">简要概述&lt;/h2>
&lt;p>在一定&lt;a href="https://docs.cilium.io/en/latest/network/kubernetes/kubeproxy-free/#kubernetes-without-kube-proxy">内核版本&lt;/a>下，&amp;ldquo;cilium&amp;rdquo; 已经可以完全替代 &amp;ldquo;kube-proxy&amp;rdquo; 组件的功能了，如处理 k8s 服务类型为：ClusterIP, NodePort, LoadBalancer 等流量转发。&lt;/p>
&lt;h2 id="如何启用功能">如何启用功能&lt;/h2>
&lt;h3 id="更改配置">更改配置&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>apiVersion: v1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>kind: ConfigMap
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>metadata:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> name: cilium-config
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> namespace: kube-system
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>data:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>......
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> kube-proxy-replacement: &amp;#34;true&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>......
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>在配置中把 &amp;ldquo;kube-proxy-replacement&amp;rdquo; 设置为 &amp;ldquo;true&amp;rdquo; 开启。&lt;/p>
&lt;h3 id="验证状态">验证状态&lt;/h3>
&lt;p>登录至 &amp;ldquo;cilium&amp;rdquo; 容器内运行以下指令查看状态：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>cilium status --verbose
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>如下，各功能启用状态：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>KubeProxyReplacement Details:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Status: True
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Socket LB: Enabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Socket LB Tracing: Enabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Socket LB Coverage: Full
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Devices: enx0826ae396977 192.168.0.2 (Direct Routing), wlp0s20f3 192.168.0.2
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Mode: SNAT
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Backend Selection: Random
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Session Affinity: Enabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Graceful Termination: Enabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> NAT46/64 Support: Disabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> XDP Acceleration: Disabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Services:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - ClusterIP: Enabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - NodePort: Enabled (Range: 30000-32767)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - LoadBalancer: Enabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - externalIPs: Enabled
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - HostPort: Enabled
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="验证功能">验证功能&lt;/h3>
&lt;ul>
&lt;li>创建以下资源：&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">---&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">v1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Pod&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">creationTimestamp&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">null&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">run&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">containers&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">image&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">registry.cn-hangzhou.aliyuncs.com/kube-image-repo/nginx:1.23.2&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">resources&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>{}&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">ports&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">containerPort&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">80&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dnsPolicy&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">ClusterFirst&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">restartPolicy&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Always&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">status&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>{}&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#000">---&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">v1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Service&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">creationTimestamp&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">null&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">run&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">ports&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">port&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">80&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">protocol&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">TCP&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">targetPort&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">80&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">selector&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">run&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">NodePort&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>查看 Pod、Service 状态：&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>$ kubectl get pods,services -l &lt;span style="color:#000">run&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>nginx -o wide
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>pod/nginx 1/1 Running &lt;span style="color:#0000cf;font-weight:bold">0&lt;/span> 79s 192.168.201.4 192.168.0.2 &amp;lt;none&amp;gt; &amp;lt;none&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>S&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> AGE SELECTOR
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>service/nginx NodePort 10.233.90.187 &amp;lt;none&amp;gt; 80:32515/TCP 79s &lt;span style="color:#000">run&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>nginx
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>查看 cilium 转发状态：&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>$ kubectl &lt;span style="color:#204a87">exec&lt;/span> -i -t cilium-mzzk6 -n kube-system -- cilium service list
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ID Frontend Service Type Backend
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#0000cf;font-weight:bold">1&lt;/span> 10.233.0.1:443 ClusterIP &lt;span style="color:#000">1&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&amp;gt; 192.168.0.2:6443 &lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>active&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#0000cf;font-weight:bold">11&lt;/span> 10.233.0.10:9153 ClusterIP &lt;span style="color:#000">1&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&amp;gt; 192.168.201.3:9153 &lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>active&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#0000cf;font-weight:bold">12&lt;/span> 10.233.0.10:53 ClusterIP &lt;span style="color:#000">1&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&amp;gt; 192.168.201.3:53 &lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>active&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#0000cf;font-weight:bold">13&lt;/span> 10.233.166.209:443 ClusterIP &lt;span style="color:#000">1&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&amp;gt; 192.168.201.12:4443 &lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>active&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#0000cf;font-weight:bold">25&lt;/span> 10.233.2.226:2746 ClusterIP &lt;span style="color:#000">1&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&amp;gt; 192.168.201.7:2746 &lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>active&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>......
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#0000cf;font-weight:bold">37&lt;/span> 192.168.0.2:32515 NodePort &lt;span style="color:#000">1&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&amp;gt; 192.168.201.4:80 &lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>active&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#0000cf;font-weight:bold">38&lt;/span> 0.0.0.0:32515 NodePort &lt;span style="color:#000">1&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&amp;gt; 192.168.201.4:80 &lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>active&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>验证服务访问：&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>$ curl &amp;#39;http://192.168.0.2:32515&amp;#39;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;lt;!DOCTYPE html&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;lt;html&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;lt;head&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;lt;title&amp;gt;Welcome to nginx!&amp;lt;/title&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>......
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;lt;/body&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;lt;/html&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="常见几种用法">常见几种用法&lt;/h2>
&lt;h3 id="指定网卡用于-nodeport-服务">指定网卡用于 NodePort 服务&lt;/h3>
&lt;p>应用场景：当宿主存在多网卡时，避免 &amp;ldquo;Service&amp;rdquo; 为 &amp;ldquo;NodePort&amp;rdquo; 类型的资源监听在非期望的网段上，如未配置好防火墙则可能导致意外数据暴露。&lt;/p>
&lt;ul>
&lt;li>该实验宿主存在以下网卡&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>$ ip addr list
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>2: wlp0s20f3: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc noqueue state UP group default qlen 1000
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> inet 10.5.56.241/24 brd 10.5.56.255 scope global dynamic noprefixroute wlp0s20f3
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>3: enx0826ae396977: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> inet 192.168.0.2/24 brd 192.168.0.255 scope global noprefixroute enx0826ae396977
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>网卡 &amp;ldquo;wlp0s20f3&amp;rdquo;、&amp;ldquo;enx0826ae396977&amp;rdquo; 分别配置了 &amp;ldquo;10.5.56.241/24&amp;rdquo;、&amp;ldquo;192.168.0.2/24&amp;rdquo; 地址。&lt;/p>
&lt;ul>
&lt;li>创建 NodePort 类型的服务&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">v1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Service&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">cilium-ingress&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">namespace&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">kube-system&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">cilium.io/ingress&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">ports&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">http&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">port&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">80&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">protocol&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">TCP&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">nodePort&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">30080&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">NodePort&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>此时监听在 NodePort 的地址&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>$ cilium service list
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ID Frontend Service Type Backend
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>10 10.233.0.1:443 ClusterIP 1 =&amp;gt; 192.168.0.2:6443 (active)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>11 10.233.124.160:80 ClusterIP
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>12 192.168.0.2:30080 NodePort
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>14 0.0.0.0:30080 NodePort
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>15 10.233.148.250:80 ClusterIP 1 =&amp;gt; 192.168.0.2:4244 (active)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>16 10.233.46.189:80 ClusterIP 1 =&amp;gt; 192.168.201.4:4245 (active)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17 10.233.49.29:80 ClusterIP 1 =&amp;gt; 192.168.201.14:8081 (active)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>18 10.233.216.132:2746 ClusterIP 1 =&amp;gt; 192.168.201.1:2746 (active)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>19 10.5.56.241:30080 NodePort
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>也通过 &amp;ldquo;bpftool net&amp;rdquo; 查看当前绑定在 &amp;ldquo;tc&amp;rdquo; 阶段的网卡有哪些：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>$ bpftool net
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>xdp:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>tc:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>wlp0s20f3&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>2&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_from_netdev-wlp0s20f3 id &lt;span style="color:#0000cf;font-weight:bold">19355&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>wlp0s20f3&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>2&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/egress cil_to_netdev-wlp0s20f3 id &lt;span style="color:#0000cf;font-weight:bold">19360&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>enx0826ae396977&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>3&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_from_netdev-enx0826ae396977 id &lt;span style="color:#0000cf;font-weight:bold">19340&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>enx0826ae396977&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>3&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/egress cil_to_netdev-enx0826ae396977 id &lt;span style="color:#0000cf;font-weight:bold">19341&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_net&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>4&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_to_host-cilium_net id &lt;span style="color:#0000cf;font-weight:bold">19325&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_host&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>5&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_to_host-cilium_host id &lt;span style="color:#0000cf;font-weight:bold">19304&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_host&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>5&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/egress cil_from_host-cilium_host id &lt;span style="color:#0000cf;font-weight:bold">19284&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc96ee90fabd66&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>93&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_from_container-lxc96ee90fabd66 id &lt;span style="color:#0000cf;font-weight:bold">19327&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc5f977feb7c71&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>95&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_from_container-lxc5f977feb7c71 id &lt;span style="color:#0000cf;font-weight:bold">19262&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc442d93d4a07e&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>99&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_from_container-lxc442d93d4a07e id &lt;span style="color:#0000cf;font-weight:bold">19300&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc3d8018e15dbd&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>101&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_from_container-lxc3d8018e15dbd id &lt;span style="color:#0000cf;font-weight:bold">19313&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc_health&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>145&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> clsact/ingress cil_from_container-lxc_health id &lt;span style="color:#0000cf;font-weight:bold">19333&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>flow_dissector:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>此时可以通过 &amp;ldquo;telnet 10.5.56.241 30080&amp;rdquo; 联通，当并不希望在该网卡上监听服务。&lt;/p>
&lt;ul>
&lt;li>配置 &amp;ldquo;cilium-config&amp;rdquo; 中的 &amp;ldquo;devices&amp;rdquo; 参数&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>apiVersion: v1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>kind: ConfigMap
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>metadata:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> name: cilium-config
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> namespace: kube-system
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>data:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ......
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> devices: &amp;#34;lxc+ enx0826ae396977&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ......
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>多网卡情况下 &amp;ldquo;devices&amp;rdquo; 中间使用空格隔开，如：&amp;ldquo;eth0 em3 bind1&amp;rdquo;。以上配置说明仅在 &amp;ldquo;lxc&amp;rdquo; 开头与名为 &amp;ldquo;enx0826ae396977&amp;rdquo; 网卡上处理。&lt;/p>
&lt;p>在通过 &amp;ldquo;bpftool net&amp;rdquo; 或者 &amp;ldquo;cilium service list&amp;rdquo; 查看信息，是否满足需求：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>$ bpftool net
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>xdp:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>tc:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>enx0826ae396977(3) clsact/ingress cil_from_netdev-enx0826ae396977 id 21450
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>enx0826ae396977(3) clsact/egress cil_to_netdev-enx0826ae396977 id 21447
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_net(4) clsact/ingress cil_to_host-cilium_net id 21434
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_host(5) clsact/ingress cil_to_host-cilium_host id 21355
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_host(5) clsact/egress cil_from_host-cilium_host id 21410
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc96ee90fabd66(93) clsact/ingress cil_from_netdev-lxc96ee90fabd66 id 21500
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc96ee90fabd66(93) clsact/egress cil_to_netdev-lxc96ee90fabd66 id 21502
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc5f977feb7c71(95) clsact/ingress cil_from_netdev-lxc5f977feb7c71 id 21494
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc5f977feb7c71(95) clsact/egress cil_to_netdev-lxc5f977feb7c71 id 21491
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc442d93d4a07e(99) clsact/ingress cil_from_netdev-lxc442d93d4a07e id 21473
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc442d93d4a07e(99) clsact/egress cil_to_netdev-lxc442d93d4a07e id 21475
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc3d8018e15dbd(101) clsact/ingress cil_from_netdev-lxc3d8018e15dbd id 21463
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc3d8018e15dbd(101) clsact/egress cil_to_netdev-lxc3d8018e15dbd id 21461
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc_health(155) clsact/ingress cil_from_container-lxc_health id 21362
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>flow_dissector:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>这里需注意下为什么要带上 &amp;ldquo;lxc&amp;rdquo; 开头的网卡，如果缺失 &amp;ldquo;bpftool net&amp;rdquo; 查看的数据为：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>$ bpftool net
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>xdp:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>tc:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>enx0826ae396977(3) clsact/ingress cil_from_netdev-enx0826ae396977 id 19760
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>enx0826ae396977(3) clsact/egress cil_to_netdev-enx0826ae396977 id 19762
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_net(4) clsact/ingress cil_to_host-cilium_net id 19723
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_host(5) clsact/ingress cil_to_host-cilium_host id 19706
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cilium_host(5) clsact/egress cil_from_host-cilium_host id 19665
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc96ee90fabd66(93) clsact/ingress cil_from_container-lxc96ee90fabd66 id 19691
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc5f977feb7c71(95) clsact/ingress cil_from_container-lxc5f977feb7c71 id 19682
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc442d93d4a07e(99) clsact/ingress cil_from_container-lxc442d93d4a07e id 19733
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc3d8018e15dbd(101) clsact/ingress cil_from_container-lxc3d8018e15dbd id 19670
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>lxc_health(147) clsact/ingress cil_from_container-lxc_health id 19747
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>flow_dissector:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>可以看到在 &amp;ldquo;lxc&amp;rdquo; 开头的网卡仅剩 &amp;ldquo;clsact/ingress&amp;rdquo; hook 钩子了，丢失了 &amp;ldquo;clsact/egress&amp;rdquo; 这种情况下在使用 &amp;ldquo;cilium-envoy&amp;rdquo; 会无法路由到后端，观察到是 &amp;ldquo;reserved:ingress&amp;rdquo; 的 ip 无法与具体的 Pod 联通，具体原因待细查。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>$ cilium ip list | grep reserved
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>0.0.0.0/0 reserved:world
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>10.5.56.241/32 reserved:host
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> reserved:kube-apiserver
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>192.168.0.2/32 reserved:host
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> reserved:kube-apiserver
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>192.168.201.4/32 reserved:health
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>192.168.201.12/32 reserved:ingress
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>192.168.201.13/32 reserved:host
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> reserved:kube-apiserver
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>$
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>可在宿主上 &amp;ldquo;tcpdump&amp;rdquo; 具体 Pod 网卡数据包：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>$ tcpdump -i lxc442d93d4a07e -nn
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>......
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.709985 IP 192.168.201.12.43687 &amp;gt; 192.168.201.1.2746: Flags [S], seq 3062515778, win 64240, options [mss 1460,sackOK,TS val 2429471181 ecr 0,nop,wscale 7], length 0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.710010 IP 192.168.201.1.2746 &amp;gt; 192.168.201.12.43687: Flags [S.], seq 955549526, ack 3062515779, win 65160, options [mss 1460,sackOK,TS val 2974496186 ecr 2429468135,nop,wscale 7], length 0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.710058 IP 192.168.201.1.2746 &amp;gt; 192.168.201.12.43687: Flags [S.], seq 955549526, ack 3062515779, win 65160, options [mss 1460,sackOK,TS val 2974496186 ecr 2429468135,nop,wscale 7], length 0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.741919 IP 192.168.201.13 &amp;gt; 192.168.201.1: ICMP host 192.168.201.12 unreachable, length 68
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.741954 IP 192.168.201.13 &amp;gt; 192.168.201.1: ICMP host 192.168.201.12 unreachable, length 68
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.741973 IP 192.168.201.13 &amp;gt; 192.168.201.1: ICMP host 192.168.201.12 unreachable, length 68
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.741990 IP 192.168.201.13 &amp;gt; 192.168.201.1: ICMP host 192.168.201.12 unreachable, length 68
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>17:26:21.742008 IP 192.168.201.13 &amp;gt; 192.168.201.1: ICMP host 192.168.201.12 unreachable, length 68
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>......
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>其中 &amp;ldquo;reserved:ingress = 192.168.201.12&amp;rdquo; 无法与后端 &amp;ldquo;Pod 192.168.201.1&amp;rdquo; 建立 TCP 连接，错误 &amp;ldquo;ICMP unreachable&amp;rdquo;。&lt;/p>
&lt;h3 id="集群流量策略">集群流量策略&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>internalTrafficPolicy&lt;/th>
&lt;th>externalTrafficPolicy&lt;/th>
&lt;th>南北向流量&lt;/th>
&lt;th>东西向流量&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Cluster&lt;/td>
&lt;td>Cluster&lt;/td>
&lt;td>所有节点可达&lt;/td>
&lt;td>所有节点可达&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Cluster&lt;/td>
&lt;td>Local&lt;/td>
&lt;td>仅被访问节点&lt;/td>
&lt;td>所有节点可达&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Local&lt;/td>
&lt;td>Cluster&lt;/td>
&lt;td>所有节点可达&lt;/td>
&lt;td>仅被访问节点&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Local&lt;/td>
&lt;td>Local&lt;/td>
&lt;td>仅被访问节点&lt;/td>
&lt;td>仅被访问节点&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table></description></item><item><title>Docs: 使用 BGP</title><link>https://opsaid.net/docs/cloud-native/networking/cilium/bgp-enable/</link><pubDate>Sun, 08 Dec 2024 12:23:14 +0800</pubDate><guid>https://opsaid.net/docs/cloud-native/networking/cilium/bgp-enable/</guid><description>
&lt;h2 id="简要概述">简要概述&lt;/h2>
&lt;h3 id="为什么需要-bgp">为什么需要 BGP&lt;/h3>
&lt;p>&lt;strong>1. Service IP 宣告 (LoadBalancer 类型服务）&lt;/strong>&lt;/p>
&lt;p>当在 Kubernetes 中创建一个 LoadBalancer 类型的 Service 资源时，Cilium 可以通过 BGP 将分配给该资源的 &amp;ldquo;External IP&amp;rdquo; 宣告给 ToR 交换机。这样，外部网络就知道如何将流量路由到这个 Service。&lt;/p>
&lt;p>&lt;strong>2. Pod IP 宣告 (当非 HTTP 协议需对外，如数据库实例等）&lt;/strong>&lt;/p>
&lt;p>在某些网络架构中（需为了避免 NAT，实现 Pod IP 的直接可达性，提供效率），Cilium 可以将分配给每个节点的 Pod CIDR 或者甚至单个 Pod IP 宣告给外部网络。这使得外部网络可以直接路由到 Pod IP，而不需要经过 NAT 的转换。&lt;/p>
&lt;p>&lt;strong>3. 集群间路由（多集群组建为大规模 Mesh）&lt;/strong>&lt;/p>
&lt;p>如果你有多个 Kubernetes 集群，BGP 可以用来在它们之间宣告路由，实现跨集群通信。&lt;/p>
&lt;h3 id="bgp-实现方式">BGP 实现方式&lt;/h3>
&lt;p>Cilium 通过集成 &lt;a href="https://github.com/osrg/gobgp">gobgp&lt;/a> 这样的外部 BGP Speaker 实现。&lt;/p>
&lt;p>在组件 &lt;a href="">cilium-agent&lt;/a> 中代码 &amp;ldquo;github.com/cilium/cilium/pkg/bgpv1/gobgp&amp;rdquo; 实现了 bgp 服务。&lt;/p>
&lt;h2 id="在宿主上">在宿主上&lt;/h2>
&lt;blockquote>
&lt;blockquote>
&lt;p>以下配置基于 &amp;ldquo;cilium/v1.14.17&amp;rdquo;、&amp;ldquo;cilium/v1.16.12&amp;rdquo; 分析。&lt;/p>
&lt;/blockquote>
&lt;/blockquote>
&lt;h3 id="确认开启-bgp-特性">确认开启 bgp 特性&lt;/h3>
&lt;p>确认已开启 cilium bgp 控制平面：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span># cilium config view | grep bgp
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>enable-bgp-control-plane true
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>#
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>使用 crd 配置 bgp，在 cilium 中存在两种类型，分别为 &lt;a href="https://opsaid.net/docs/cloud-native/networking/cilium/bgp-enable/#%E9%85%8D%E7%BD%AE-ciliumbgppeeringpolicy">CiliumBGPPeeringPolicy&lt;/a>（v1.16 版本之前，现标记废弃）、&lt;a href="https://opsaid.net/docs/cloud-native/networking/cilium/bgp-enable/#%E9%85%8D%E7%BD%AE-ciliumbgpclusterconfig">CiliumBGPClusterConfig&lt;/a>（v1.16 及之后版本）。&lt;/p>
&lt;p>禁止同时使用两者资源，若两个资源同时存在且 cilium 通过节点选择器同时匹配到两者时，系统将优先采用 CiliumBGPPeeringPolicy 的配置。&lt;/p>
&lt;h2 id="配置-ciliumbgppeeringpolicy">配置 CiliumBGPPeeringPolicy&lt;/h2>
&lt;p>&lt;em>&lt;strong>在 cilium v1.15 及以下版本使用。&lt;/strong>&lt;/em>&lt;/p>
&lt;h3 id="创建-bgp-peer">创建 BGP Peer&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>apiVersion: &lt;span style="color:#4e9a06">&amp;#34;cilium.io/v2alpha1&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>kind: CiliumBGPPeeringPolicy
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>metadata:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> name: cilium-bgp
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>spec:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic"># 在哪些节点上开启与 peer 建立连接&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> nodeSelector:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> matchLabels:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> bgp: test1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> virtualRouters:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - localASN: &lt;span style="color:#0000cf;font-weight:bold">65415&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic"># 通告 pod 网段&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> exportPodCIDR: &lt;span style="color:#204a87">true&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic"># 通告哪些 service 路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> serviceSelector:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> matchLabels:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cilium.io/announce-bgp-service: &lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> neighbors:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - peerAddress: &lt;span style="color:#4e9a06">&amp;#39;192.168.17.252/32&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> peerASN: &lt;span style="color:#0000cf;font-weight:bold">65415&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>对节点存在标签 &amp;ldquo;bgp=test1&amp;rdquo; 则与 bgp peer 地址为 &amp;ldquo;192.168.17.252&amp;rdquo; 且 &amp;ldquo;as=65415&amp;rdquo; 建立连接。&lt;/p>
&lt;ul>
&lt;li>对特定接口打标签&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>kubectl label node 192.168.17.142 &lt;span style="color:#000">bgp&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>test1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>对节点绑定标签以满足 bgp peer 建立连接，注意一个节点不能同时匹配多个 CiliumBGPPeeringPolicy 资源，否则无法启用。&lt;/p>
&lt;h2 id="配置-ciliumbgpclusterconfig">配置 CiliumBGPClusterConfig&lt;/h2>
&lt;p>&lt;em>&lt;strong>在 cilium v1.16 及以上版本新增 CiliumBGPClusterConfig 资源，同时废弃以上资源。&lt;/strong>&lt;/em>&lt;/p>
&lt;h3 id="资源定义">资源定义&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>CRD&lt;/th>
&lt;th>用途&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>CiliumBGPClusterConfig&lt;/td>
&lt;td>定义 bgp 实例，通过 &lt;code>name&lt;/code> 唯一标识&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CiliumBGPPeerConfig&lt;/td>
&lt;td>每个 bgp 实例中关联 peer 的个性配置&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CiliumBGPAdvertisement&lt;/td>
&lt;td>通告路由的规则&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CiliumBGPNodeConfig&lt;/td>
&lt;td>-&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CiliumBGPNodeConfigOverride&lt;/td>
&lt;td>-&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="创建-bgp-实例">创建 bgp 实例&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">---&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">cilium.io/v2alpha1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">CiliumBGPClusterConfig&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">cilium-bgp&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">nodeSelector&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">matchLabels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">rack&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">rack0&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">bgpInstances&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;instance-65000&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">localASN&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">65000&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peers&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;peer-65000-tor1&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peerASN&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">65000&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peerAddress&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">192.168.0.149&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peerConfigRef&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;cilium-peer&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;peer-65000-tor2&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peerASN&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">65000&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peerAddress&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">192.168.0.121&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peerConfigRef&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;cilium-peer&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>与两个 peer &amp;ldquo;192.168.0.149&amp;rdquo;, &amp;ldquo;192.168.0.121&amp;rdquo; 建立连接，各 peer 配置见资源 &amp;ldquo;cilium-peer&amp;rdquo;&lt;/p>
&lt;h3 id="bgp-peer-配置">BGP Peer 配置&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">---&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">cilium.io/v2alpha1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">CiliumBGPPeerConfig&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">cilium-peer&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">timers&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">holdTimeSeconds&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">9&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">keepAliveTimeSeconds&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">3&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic">#authSecretRef: bgp-auth-secret&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">ebgpMultihop&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">4&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">gracefulRestart&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">enabled&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">true&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">restartTimeSeconds&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">15&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">families&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">afi&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">ipv4&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">safi&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">unicast&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">advertisements&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 匹配 CiliumBGPAdvertisement 的标签&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">matchLabels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">advertise&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;bgp&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">transport&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">peerPort&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">179&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>比如认证、超时、通告 ip 地址族等个性化配置。&lt;/p>
&lt;h3 id="bgp-通告">BGP 通告&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">---&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">cilium.io/v2alpha1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">CiliumBGPAdvertisement&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">bgp-advertisements&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">advertise&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">bgp&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">advertisements&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 通告 Service VIP&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">advertisementType&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;Service&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">service&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">addresses&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#000">ClusterIP&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#000">LoadBalancerIP&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 通告 POD 网段&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">advertisementType&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;PodCIDR&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">attributes&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">communities&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">standard&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000;font-weight:bold">[&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;65000:99&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000;font-weight:bold">]&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">localPreference&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">99&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>通告 Service&lt;/li>
&lt;/ul>
&lt;p>当类型为 &amp;ldquo;LoadBalancerIP&amp;rdquo; 时，需确保 k8s 集群能分配 IP，这里也使用 cilium &lt;a href="https://docs.cilium.io/en/latest/network/lb-ipam/">LB IPAM&lt;/a> 特性。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;cilium.io/v2alpha1&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">CiliumLoadBalancerIPPool&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;default&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">blocks&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">cidr&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;192.168.253.0/24&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="应用场景">应用场景&lt;/h2>
&lt;h3 id="配置-router-id">配置 Router ID&lt;/h3>
&lt;p>如果集群运行的是 ipv4 或 ipv4/ipv6 双栈，cilium 会自动使用宿主 ipv4 上的 IP 作为 Router ID。&lt;/p>
&lt;p>如果仅运行 ipv6 或者需要手工配置的话，需要添加注解：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>kubectl annotate node 192.168.17.142 cilium.io/bgp-virtual-router.65415&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;router-id=192.168.17.142&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="配置宿主监听端口">配置宿主监听端口&lt;/h3>
&lt;p>宿主通过随机端口与远端 179 通讯：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>kubectl logs -f cilium-nlkxs -n kube-system --tail&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#0000cf;font-weight:bold">10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>level=info msg=&amp;#34;type:STATE peer:{conf:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415} state:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415 session_state:OPENSENT router_id:\&amp;#34;&amp;lt;nil&amp;gt;\&amp;#34;} transport:{local_address:\&amp;#34;192.168.17.140\&amp;#34; local_port:50409 remote_port:179}}&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>level=info msg=&amp;#34;type:STATE peer:{conf:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415} state:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415 session_state:IDLE router_id:\&amp;#34;&amp;lt;nil&amp;gt;\&amp;#34;} transport:{local_address:\&amp;#34;192.168.17.140\&amp;#34; local_port:50409 remote_port:179}}&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>level=info msg=&amp;#34;type:STATE peer:{conf:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415} state:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415 session_state:ACTIVE router_id:\&amp;#34;&amp;lt;nil&amp;gt;\&amp;#34;} transport:{local_address:\&amp;#34;192.168.17.140\&amp;#34; local_port:50409 remote_port:179}}&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>level=info msg=&amp;#34;type:STATE peer:{conf:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415} state:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415 session_state:OPENSENT router_id:\&amp;#34;&amp;lt;nil&amp;gt;\&amp;#34;} transport:{local_address:\&amp;#34;192.168.17.140\&amp;#34; local_port:47671 remote_port:179}}&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>level=info msg=&amp;#34;Peer Up&amp;#34; Key=192.168.17.252 State=BGP_FSM_OPENCONFIRM Topic=Peer asn=65415 component=gobgp.BgpServerInstance subsys=bgp-control-plane
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>level=info msg=&amp;#34;type:STATE peer:{conf:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415} state:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415 session_state:OPENCONFIRM router_id:\&amp;#34;192.168.17.252\&amp;#34;} transport:{local_address:\&amp;#34;192.168.17.140\&amp;#34; local_port:47671 remote_port:179}}&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>level=info msg=&amp;#34;type:STATE peer:{conf:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415} state:{local_asn:65415 neighbor_address:\&amp;#34;192.168.17.252\&amp;#34; peer_asn:65415 session_state:ESTABLISHED router_id:\&amp;#34;192.168.17.252\&amp;#34;} transport:{local_address:\&amp;#34;192.168.17.140\&amp;#34; local_port:47671 remote_port:179}}&amp;#34;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>通过主动标记设置本地端口：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>kubectl annotate node 192.168.17.142 cilium.io/bgp-virtual-router.65415&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;local-port=61179&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="通告-loadbalancer-ip">通告 LoadBalancer IP&lt;/h3>
&lt;blockquote>
&lt;blockquote>
&lt;p>以下配置基于 &amp;ldquo;cilium/v1.14.17&amp;rdquo; 分析。&lt;/p>
&lt;/blockquote>
&lt;/blockquote>
&lt;p>&lt;strong>1. 创建示例服务&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">apps/v1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Deployment&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">app&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">replicas&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">selector&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">matchLabels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">app&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">template&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">app&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">containers&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">image&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">registry.cn-hangzhou.aliyuncs.com/opsaid/nginx:1.23-debian-11&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">securityContext&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">allowPrivilegeEscalation&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">false&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">capabilities&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">drop&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#000">ALL&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">runAsNonRoot&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">true&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">securityContext&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">seccompProfile&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">RuntimeDefault&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>创建 &amp;ldquo;nginx&amp;rdquo; 应用默认在 &amp;ldquo;8080&amp;rdquo; 端口监听。&lt;/p>
&lt;p>&lt;strong>2. 创建 &amp;ldquo;LoadBalancer&amp;rdquo; 类型 &amp;ldquo;Service&amp;rdquo;&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">v1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Service&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 与 CiliumBGPPeeringPolicy 联动&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">cilium.io/announce-bgp-service&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">selector&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">app&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nginx&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">ports&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">port&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">80&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">targetPort&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">8080&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 前提条件&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">externalTrafficPolicy&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Cluster&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 如果存在多个提供方，明确使用 cilium bgp 分配&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">loadBalancerClass&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;io.cilium/bgp-control-plane&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">type&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">LoadBalancer&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>对 &amp;ldquo;default&amp;rdquo; 空间下标签为 &amp;ldquo;app=nginx&amp;rdquo; 创建 &amp;ldquo;LoadBalancer&amp;rdquo;，此时访问 &amp;ldquo;Service&amp;rdquo; 对外的端口为 &amp;ldquo;80&amp;rdquo; 会自动转发至应用 &amp;ldquo;8080&amp;rdquo; 服务。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span># kubectl get service nginx
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>nginx LoadBalancer 10.233.46.209 &amp;lt;pending&amp;gt; 80:31624/TCP 2m40s
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>#
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>创建成功后，因为集群本身不支持自动分配 IP，所以 &amp;ldquo;EXTERNAL-IP&amp;rdquo; 会一直处于 &amp;ldquo;pending&amp;rdquo; 状态。&lt;/p>
&lt;p>&lt;strong>3. 记录当前 TOR 交换机 BGP 路由&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>&amp;gt;display bgp routing-table
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> BGP Local router ID is 192.168.17.252
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Status codes: * - valid, &amp;gt; - best, d - damped, a - add path,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> h - history, i - internal, s - suppressed, S - Stale
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Origin : i - IGP, e - EGP, ? - incomplete
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Total Number of Routes: 4
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Network NextHop MED LocPrf PrefVal Path/Ogn
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> *&amp;gt;i 192.168.200.0/24 192.168.17.140 100 0 i
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> *&amp;gt;i 192.168.201.0/24 192.168.17.141 100 0 i
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> *&amp;gt;i 192.168.202.0/24 192.168.17.142 100 0 i
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> *&amp;gt;i 192.168.203.0/24 192.168.17.143 100 0 i
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>仅到集群 POD CIDR 路由。&lt;/p>
&lt;p>&lt;strong>3. 手工更改 &amp;ldquo;Service&amp;rdquo; 中 &amp;ldquo;status&amp;rdquo; 地址&lt;/strong>&lt;/p>
&lt;p>在 &amp;ldquo;cilium v1.14&amp;rdquo; 版本下需要更改，&amp;ldquo;v1.16&amp;rdquo; 版本会自动分配 IP。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">cat &amp;lt;&amp;lt;EOF &amp;gt; patch.json&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>{&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">&amp;#34;status&amp;#34;: &lt;/span>{&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">&amp;#34;loadBalancer&amp;#34;: &lt;/span>{&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">&amp;#34;ingress&amp;#34;: &lt;/span>&lt;span style="color:#000;font-weight:bold">[&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>{&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">&amp;#34;ip&amp;#34;: &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;192.168.253.1&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>}&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000;font-weight:bold">]&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>}&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>}&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>}&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#000">EOF&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>kubectl patch service nginx &lt;span style="color:#4e9a06">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#4e9a06">&lt;/span> --namespace default &lt;span style="color:#4e9a06">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#4e9a06">&lt;/span> --type merge &lt;span style="color:#4e9a06">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#4e9a06">&lt;/span> --patch-file patch.json &lt;span style="color:#4e9a06">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#4e9a06">&lt;/span> --subresource status
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span># kubectl get service nginx
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>nginx LoadBalancer 10.233.46.209 192.168.253.1 80:31624/TCP 8m9s
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span># ^C
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>这里为什么需要手工更改 &amp;ldquo;status&amp;rdquo; 信息？&lt;/p>
&lt;p>&lt;strong>4. 再次验证 TOR 是否学到路由&lt;/strong>&lt;/p>
&lt;pre tabindex="0">&lt;code class="language-test" data-lang="test">&amp;gt;display bgp routing-table
BGP Local router ID is 192.168.17.252
Status codes: * - valid, &amp;gt; - best, d - damped, a - add path,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 8
Network NextHop MED LocPrf PrefVal Path/Ogn
*&amp;gt;i 192.168.200.0/24 192.168.17.140 100 0 i
*&amp;gt;i 192.168.201.0/24 192.168.17.141 100 0 i
*&amp;gt;i 192.168.202.0/24 192.168.17.142 100 0 i
*&amp;gt;i 192.168.203.0/24 192.168.17.143 100 0 i
*&amp;gt;i 192.168.253.1/32 192.168.17.140 100 0 i
* i 192.168.17.141 100 0 i
* i 192.168.17.142 100 0 i
* i 192.168.17.143 100 0 i
&amp;gt;
&lt;/code>&lt;/pre>&lt;p>可以观察到 TOR 交换机学习到对端通告的 &amp;ldquo;192.168.253.1/32&amp;rdquo; 路由并标记 &amp;ldquo;192.168.17.140&amp;rdquo; 为下一跳最优。&lt;/p>
&lt;p>&lt;strong>5. 通告 LoadBalancer IP 的前提条件&lt;/strong>&lt;/p>
&lt;p>前提条件：&lt;/p>
&lt;ol>
&lt;li>需 &amp;ldquo;externalTrafficPolicy&amp;rdquo; 为 &amp;ldquo;Cluster&amp;rdquo; 类型；&lt;/li>
&lt;li>需 &amp;ldquo;LoadBalancer&amp;rdquo; 存在 &amp;ldquo;status.loadBalancer.ingress[].ip&amp;rdquo; 值；&lt;/li>
&lt;li>如果存在多个负载均衡器，需明确 &amp;ldquo;loadBalancerClass&amp;rdquo; 值；&lt;/li>
&lt;/ol>
&lt;p>当集群本身不支持自动分配 LoadBalancer 类型 Service IP 时，需要手工添加。&lt;/p>
&lt;p>此版本 &amp;ldquo;cilium/v1.14.17&amp;rdquo; 关键判断代码如下：&lt;/p>
&lt;blockquote>
&lt;blockquote>
&lt;p>github.com/cilium/cilium/pkg/bgpv1/manager/reconcile.go&lt;/p>
&lt;/blockquote>
&lt;/blockquote>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-golang" data-lang="golang">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ce5c00;font-weight:bold">......&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// Ignore externalTrafficPolicy == Local &amp;amp;&amp;amp; no local endpoints
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">svc&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Spec&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">ExternalTrafficPolicy&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> &lt;span style="color:#000">slim_corev1&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">ServiceExternalTrafficPolicyLocal&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">&amp;amp;&amp;amp;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">!&lt;/span>&lt;span style="color:#000">hasLocalEndpoints&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">svc&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">ls&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">return&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">var&lt;/span> &lt;span style="color:#000">desiredRoutes&lt;/span> &lt;span style="color:#000;font-weight:bold">[]&lt;/span>&lt;span style="color:#000">netip&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Prefix&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">for&lt;/span> &lt;span style="color:#000">_&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">ingress&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">range&lt;/span> &lt;span style="color:#000">svc&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Status&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">LoadBalancer&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">Ingress&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">ingress&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">IP&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;&amp;#34;&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">continue&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">addr&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">:=&lt;/span> &lt;span style="color:#000">netip&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">ParseAddr&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">ingress&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">IP&lt;/span>&lt;span style="color:#000;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">if&lt;/span> &lt;span style="color:#000">err&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">!=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">nil&lt;/span> &lt;span style="color:#000;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">continue&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">desiredRoutes&lt;/span> &lt;span style="color:#000;font-weight:bold">=&lt;/span> &lt;span style="color:#204a87">append&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">desiredRoutes&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">netip&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">PrefixFrom&lt;/span>&lt;span style="color:#000;font-weight:bold">(&lt;/span>&lt;span style="color:#000">addr&lt;/span>&lt;span style="color:#000;font-weight:bold">,&lt;/span> &lt;span style="color:#000">addr&lt;/span>&lt;span style="color:#000;font-weight:bold">.&lt;/span>&lt;span style="color:#000">BitLen&lt;/span>&lt;span style="color:#000;font-weight:bold">()))&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ce5c00;font-weight:bold">......&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="分配-loadbalancer-ip">分配 LoadBalancer IP&lt;/h3>
&lt;p>在 &lt;a href="https://opsaid.net/docs/cloud-native/networking/cilium/bgp-enable/#%E9%80%9A%E5%91%8A-loadbalancer-ip">通告 LoadBalancer IP&lt;/a> 实验中可知，创建 LoadBalancer 资源后，会等待集群分配 &amp;ldquo;EXTERNAL-IP&amp;rdquo; 如果持续未分配则无法通告路由至上联 TOR 交换机。&lt;/p>
&lt;p>LB IPAM 是一项允许 Cilium 为 LoadBalancer 类型的 Service 分配 IP 地址的功能。在公有云环境中，此类操作通常由云服务商自动处理；但在私有云部署场景下，往往缺乏现成的 IP 分配机制。&lt;/p>
&lt;p>这里我们利用 cilium 特性，通告创建一个 CIDR 网络，允许自动分配 IP 地址：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;cilium.io/v2alpha1&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">CiliumLoadBalancerIPPool&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;default&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 在 cilium/1.14 下参数配置&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">cidrs&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">cidr&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;192.168.253.0/24&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic"># 在 cilium/1.16 下参数配置&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic">#blocks:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#8f5902;font-style:italic">#- cidr: &amp;#34;192.168.253.0/24&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>注意：&lt;/p>
&lt;ol>
&lt;li>更新IP地址池可能导致IP地址重新分配，进而引发服务IP变更；&lt;/li>
&lt;li>如果删除该资源则对已分配的 IP 也会同时回收，也就是删除已通告的 BGP 路由；&lt;/li>
&lt;li>默认情况下，LB-IPAM 会使用给定 CIDR 中的所有IP地址，所以分配是记得保留。&lt;/li>
&lt;/ol>
&lt;h2 id="其他参考">其他参考&lt;/h2>
&lt;p>&lt;a href="https://support.huawei.com/enterprise/zh/doc/DOC1100023543/96bfc311">ToR 交换机架构&lt;/a>&lt;/p></description></item></channel></rss>