为 Azure Kubernetes Fleet Manager 配置和使用跨群集网络(预览版)

适用于: ✔️车队经理 ✔️中心群集的车队经理

适用于 Azure Kubernetes Fleet Manager 的跨群集网络功能提供托管的 Cilium 多群集功能,可将 Cilium 基于 eBPF 的网络和可观测性扩展到多个群集。

Fleet Manager 支持创建多个跨群集网络配置文件,每个配置文件最多支持 255 个成员群集。 配置文件中的集群会加入一个托管式联邦网络,从而能够访问全局服务,并通过 Hubble 实现服务发现和可观测性。

平台工程师标记应参与单个跨群集网络的成员群集,并在定义网络配置文件时在选择器中指定标签。 为了便于批量管理成员关系并避免意外中断,只有在授权用户明确请求时,才会更新跨集群网络。

本文介绍如何配置跨群集网络配置文件、添加成员群集以及如何公开全局服务。

Important

Azure Kubernetes 舰队管理器预览功能可以通过自助服务方式选择性启用。 预览版按“现状”和“视供应情况”提供,它们不包括在服务级别协议和有限保证范围内。 客户支持部门会尽力为 Azure Kubernetes 舰队管理器预览功能提供部分支持。 因此,这些功能并不适合用于生产。

先决条件和限制

  • 跨群集网络最多可以有 255 个成员群集。
  • 机队管理器成员群集随时只能参与单个跨群集网络。
  • 群集必须运行 Kubernetes v1.32 或更高版本,并且已启用 Cilium 的高级容器网络服务(ACNS)。
  • 群集必须连接到 单个平面网络 (虚拟网络或多个对等网络)。
  • 不支持基于隧道的覆盖网络。
  • 无法同时部署自管理的 Cilium 多群集。
  • ACNS 设置 Cilium 版本和已启用的功能,这些功能是只读的,用户无法修改。

在您开始之前

如果您没有 Azure 试用订阅,请在开始之前创建 试用订阅

创建两个成员 AKS 群集 mbr-aks-member-1 ,并 mbr-aks-member-2 启用高级容器网络服务(ACNS)。

设置以下环境变量:

export GROUP=<resource-group>
export FLEET=<fleet-name>
export MEMBER_CLUSTER_1=mbr-aks-member-1
export MEMBER_CLUSTER_2=mbr-aks-member-2
export TRAFFIC_MANAGER_GROUP=rg-flt-tm-demo
export NETWORK_NAME=demo-network
export NETWORK_PROFILE_NAME=fccnp-demo-01

标记成员群集

标记这两个成员群集,以便将其配置为包含在跨群集网络中。

az fleet member update \
    --fleet-name ${FLEET} \
    --resource-group ${GROUP} \
    --name ${MEMBER_CLUSTER_1} \
    --labels "mesh=${NETWORK_NAME}"
az fleet member update \
    --fleet-name ${FLEET} \
    --resource-group ${GROUP} \
    --name ${MEMBER_CLUSTER_2} \
    --labels "mesh=${NETWORK_NAME}"

创建跨群集网络配置文件

使用 az fleet clustermeshprofile create 命令创建跨群集网络配置文件。

az fleet clustermeshprofile create \
    --fleet-name ${FLEET} \
    --resource-group ${GROUP} \
    --name ${NETWORK_PROFILE_NAME} \
    --member-label-selector "mesh=${NETWORK_NAME}"

虽然网络配置文件是作为 Azure 资源创建的,但尚未在各集群中应用 Cilium 多集群配置。 仍需执行以下步骤来应用和连接跨群集网络。

验证所选群集

通过向命令提供 whatif 参数 az fleet clustermeshprofile apply 来验证跨群集网络中将包含哪些群集。

az fleet clustermeshprofile apply \
    --what-if \
    --fleet-name ${FLEET} \
    --resource-group ${GROUP} \
    --name ${NETWORK_PROFILE_NAME} \
    --output table

由于我们正在创建一个新的跨群集网络,因此这两个群集均显示“添加”操作。

ClusterResourceId    	            ETag        Name  		       Action   MeshMembershipState
----------------------------------  ----------  -----------------  -------  -------------------
/subscription/…/…/mbr-aks-member-1  "fd009cd9"  mbr-aks-member-1   Add       -
/subscription/…/…/mbr-aks-member-2  "a400f86e"  mbr-aks-member-2   Add       -

连接跨集群网络

现在可以通过省略 what-if 命令中的 az fleet clustermeshprofile apply 参数来应用跨群集网络更改。

az fleet clustermeshprofile apply \
    --fleet-name ${FLEET} \
    --resource-group ${GROUP} \
    --name ${NETWORK_PROFILE_NAME} 

跨群集网络创建开始,Cilium 多群集配置将应用于所选成员群集。 创建过程是异步的,进程持续时间由要更新的群集数决定。

应用操作将运行到完成状态,并且无法中断。 运行时,可以监视每个成员的网络状态:

az fleet clustermeshprofile list-members \
    --fleet-name ${FLEET} \
    --resource-group ${GROUP} \
    --name ${NETWORK_PROFILE_NAME} \
    --query "[].{name: name, state: meshProperties.status.state}" \
    -o table
Name              State
----------------  ----------
mbr-aks-member-1  Connecting
mbr-aks-member-2  Connecting

还可以监视整体操作的状态:

az fleet clustermeshprofile show \
    --fleet-name ${FLEET} \
    --resource-group ${GROUP} \
    --name ${NETWORK_PROFILE_NAME} \
    --query "properties.status.state" \
    -o tsv

通过数据平面确认跨集群网络连接

成员的状态显示为 Connected后,将建立跨群集网络。

可以使用标准数据平面工具(如 Cilium CLI)确认连接成功。 首先,使用 az aks get-credentials 获取两个成员集群的 Kubernetes 访问凭据,并适当设置 context

az aks get-credentials \
    --resource-group $RESOURCE_GROUP \
    --name $AKS_CLUSTER_1 \
    --context cluster1

然后,使用 Cilium CLI 的状态命令查看所有成员群集是否已连接:

cilium clustermesh status --context cluster1
✅ Cluster access information is available:
  - 10.168.0.89:2379
✅ Service "clustermesh-apiserver" of type "LoadBalancer" found
✅ All 2 nodes are connected to all clusters [min:1 / avg:1.0 / max:1]
🔌 Cluster Connections:
- mbr-aks-member-2: 2/2 configured, 2/2 connected

测试负载均衡和服务发现

成功创建跨群集网络后,可以按照 官方 Cilium 多群集示例或使用下一步所示的步骤测试负载均衡。 本文档中的步骤提供有关使用 AKS 群集和机群管理器的额外指导。

注释

Fleet Manager 托管的 Cilium 多集群安装会设置 clustermesh-default-global-namespace: false,这与上游 Cilium 的默认值不同。 必须在命名空间上设置 clustermesh.cilium.io/global="true" 注解,以启用跨集群服务共享。 如果没有它,针对每个 Service 的 service.cilium.io/global 注解将不起作用。

  • 创建 mbr-aks-member-1 专用命名空间并对其进行批注,以便其内的服务有资格跨跨群集网络共享。 然后使用 Deployment 清单应用 Servicecluster1.yaml 资源。

    kubectl --context=cluster1 create namespace rebel-base-demo
    kubectl --context=cluster1 annotate namespace rebel-base-demo clustermesh.cilium.io/global="true" --overwrite
    kubectl --context=cluster1 -n rebel-base-demo apply -f https://raw.githubusercontent.com/cilium/cilium/refs/heads/main/examples/kubernetes/clustermesh/cluster1.yaml
    kubectl --context=cluster1 -n rebel-base-demo apply -f https://raw.githubusercontent.com/cilium/cilium/refs/heads/main/examples/kubernetes/clustermesh/global-service-example.yaml
    
  • mbr-aks-member-2 上应用对应项,但这次使用 cluster2.yaml 清单。

    kubectl --context=cluster2 create namespace rebel-base-demo
    kubectl --context=cluster2 annotate namespace rebel-base-demo clustermesh.cilium.io/global="true" --overwrite
    kubectl --context=cluster2 -n rebel-base-demo apply -f https://raw.githubusercontent.com/cilium/cilium/refs/heads/main/examples/kubernetes/clustermesh/cluster2.yaml
    kubectl --context=cluster2 -n rebel-base-demo apply -f https://raw.githubusercontent.com/cilium/cilium/refs/heads/main/examples/kubernetes/clustermesh/global-service-example.yaml
    
  • 在每个群集上多次运行以下命令。 观察服务群集更改,演示请求由多个群集提供服务,尽管只调用一个服务。

    kubectl --context=cluster1 -n rebel-base-demo exec -ti deployment/x-wing -- curl rebel-base
    
    {"Galaxy": "Alderaan", "Cluster": "Cluster-1"}
    {"Galaxy": "Alderaan", "Cluster": "Cluster-1"}
    {"Galaxy": "Alderaan", "Cluster": "Cluster-2"}
    
  • clustermesh.cilium.io/global(群集 1)上的 rebel-base-demo 命名空间的 mbr-aks-member-1 注解设置为 "false",以便该命名空间中的服务不再通过来自群集 1 的跨群集网络进行共享。

    kubectl --context=cluster1 annotate namespace rebel-base-demo clustermesh.cilium.io/global="false" --overwrite
    
  • 让我们验证 mbr-aks-member-1 (群集 1)可以访问 rebel-base 群集 1 上的服务,并且 mbr-aks-member-2 (群集 2)无法。

    kubectl --context=cluster1 -n rebel-base-demo exec -ti deployment/x-wing -- curl rebel-base
    

    在集群 1 上,我们只能看到本地响应,因为 Namespace 不再是全局的,而且远程端点未被导入。

    {"Galaxy": "Alderaan", "Cluster": "Cluster-1"}
    {"Galaxy": "Alderaan", "Cluster": "Cluster-1"}
    {"Galaxy": "Alderaan", "Cluster": "Cluster-1"}
    
    kubectl --context=cluster2 -n rebel-base-demo exec -ti deployment/x-wing -- curl rebel-base
    

    在群集 2 上,我们只看到本地响应,因为群集 1 上的服务不再共享。

    {"Galaxy": "Alderaan", "Cluster": "Cluster-2"}
    {"Galaxy": "Alderaan", "Cluster": "Cluster-2"}
    {"Galaxy": "Alderaan", "Cluster": "Cluster-2"}
    

更新跨群集网络

本指南演示了添加或删除群集的过程,但可以概括为:

  1. 修改要添加或删除的 Fleet Manager 成员群集上的标签。
  2. 使用 whatif 参数和 az fleet clustermeshprofile apply 命令查看跨群集网络更改。
  3. 对更改感到满意后,请通过运行相同的命令来应用这些更改,省略参数 whatif

查看更改是可选的,但建议使用,尤其是对于较大的跨群集网络,其中任何更改可能需要一些时间才能完成。

后续步骤