快速入门:将资源从 Azure Kubernetes 舰队管理器(舰队)中心群集传播到成员群集
本快速入门介绍如何将资源从 Azure Kubernetes 舰队管理器(舰队)中心群集传播到成员群集。
先决条件
如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅。
- 阅读资源传播概念概述,了解本快速入门中使用的概念和术语。
- 一个 Azure 帐户和一个有效的订阅。 创建帐户。
- 需要包含一个中心群集和多个成员群集的舰队资源。 如果没有,请参阅使用 Azure CLI 创建 Azure Kubernetes 舰队管理器资源并加入成员群集。
- 必须在中心群集中适当标记成员群集,以匹配所需的选择条件。 示例标签包括区域、环境、团队、可用性区域、节点可用性或所需的任何其他内容。
- 需要访问中心群集的 Kubernetes API。 如果没有访问权限,请参阅使用 Azure Kubernetes 舰队管理器访问舰队资源的 Kubernetes API。
使用 ClusterResourcePlacement
API 将资源传播到成员群集
ClusterResourcePlacement
API 对象用于将资源从中心群集传播到成员群集。 ClusterResourcePlacement
API 对象指定要传播的资源,以及选择成员群集时使用的放置策略。 ClusterResourcePlacement
API 对象是在中心群集中创建的,用于将资源传播到成员群集。 以下示例演示如何使用具有 PickAll
放置策略的 ClusterResourcePlacement
API 对象将命名空间传播到成员群集。
有关详细信息,请参阅将 Kubernetes 资源从中心群集传播到成员群集(预览版)和上游舰队文档。
使用
kubectl create namespace
命令创建要放置在成员群集上的命名空间。 以下示例创建名为my-namespace
的命名空间:kubectl create namespace my-namespace
在中心群集中创建
ClusterResourcePlacement
API 对象,以将命名空间传播到成员群集,然后使用kubectl apply -f
命令部署该命名空间。 以下示例ClusterResourcePlacement
创建名为crp
的对象,并使用具有PickAll
放置策略的my-namespace
命名空间将命名空间传播到所有成员群集:kubectl apply -f - <<EOF apiVersion: placement.kubernetes-fleet.io/v1beta1 kind: ClusterResourcePlacement metadata: name: crp spec: resourceSelectors: - group: "" kind: Namespace version: v1 name: my-namespace policy: placementType: PickAll EOF
使用
kubectl get clusterresourceplacement
命令检查资源传播的进度。 以下示例检查名为crp
的ClusterResourcePlacement
对象的状态:kubectl get clusterresourceplacement crp
输出应类似于以下示例输出:
NAME GEN SCHEDULED SCHEDULEDGEN APPLIED APPLIEDGEN AGE crp 2 True 2 True 2 10s
使用
kubectl describe crp
命令查看crp
对象的详细信息。 以下示例介绍名为crp
的ClusterResourcePlacement
对象:kubectl describe clusterresourceplacement crp
输出应类似于以下示例输出:
Name: crp Namespace: Labels: <none> Annotations: <none> API Version: placement.kubernetes-fleet.io/v1beta1 Kind: ClusterResourcePlacement Metadata: Creation Timestamp: 2024-04-01T18:55:31Z Finalizers: kubernetes-fleet.io/crp-cleanup kubernetes-fleet.io/scheduler-cleanup Generation: 2 Resource Version: 6949 UID: 815b1d81-61ae-4fb1-a2b1-06794be3f986 Spec: Policy: Placement Type: PickAll Resource Selectors: Group: Kind: Namespace Name: my-namespace Version: v1 Revision History Limit: 10 Strategy: Type: RollingUpdate Status: Conditions: Last Transition Time: 2024-04-01T18:55:31Z Message: found all the clusters needed as specified by the scheduling policy Observed Generation: 2 Reason: SchedulingPolicyFulfilled Status: True Type: ClusterResourcePlacementScheduled Last Transition Time: 2024-04-01T18:55:36Z Message: All 3 cluster(s) are synchronized to the latest resources on the hub cluster Observed Generation: 2 Reason: SynchronizeSucceeded Status: True Type: ClusterResourcePlacementSynchronized Last Transition Time: 2024-04-01T18:55:36Z Message: Successfully applied resources to 3 member clusters Observed Generation: 2 Reason: ApplySucceeded Status: True Type: ClusterResourcePlacementApplied Observed Resource Index: 0 Placement Statuses: Cluster Name: membercluster1 Conditions: Last Transition Time: 2024-04-01T18:55:31Z Message: Successfully scheduled resources for placement in membercluster1 (affinity score: 0, topology spread score: 0): picked by scheduling policy Observed Generation: 2 Reason: ScheduleSucceeded Status: True Type: ResourceScheduled Last Transition Time: 2024-04-01T18:55:36Z Message: Successfully Synchronized work(s) for placement Observed Generation: 2 Reason: WorkSynchronizeSucceeded Status: True Type: WorkSynchronized Last Transition Time: 2024-04-01T18:55:36Z Message: Successfully applied resources Observed Generation: 2 Reason: ApplySucceeded Status: True Type: ResourceApplied Cluster Name: membercluster2 Conditions: Last Transition Time: 2024-04-01T18:55:31Z Message: Successfully scheduled resources for placement in membercluster2 (affinity score: 0, topology spread score: 0): picked by scheduling policy Observed Generation: 2 Reason: ScheduleSucceeded Status: True Type: ResourceScheduled Last Transition Time: 2024-04-01T18:55:36Z Message: Successfully Synchronized work(s) for placement Observed Generation: 2 Reason: WorkSynchronizeSucceeded Status: True Type: WorkSynchronized Last Transition Time: 2024-04-01T18:55:36Z Message: Successfully applied resources Observed Generation: 2 Reason: ApplySucceeded Status: True Type: ResourceApplied Cluster Name: membercluster3 Conditions: Last Transition Time: 2024-04-01T18:55:31Z Message: Successfully scheduled resources for placement in membercluster3 (affinity score: 0, topology spread score: 0): picked by scheduling policy Observed Generation: 2 Reason: ScheduleSucceeded Status: True Type: ResourceScheduled Last Transition Time: 2024-04-01T18:55:36Z Message: Successfully Synchronized work(s) for placement Observed Generation: 2 Reason: WorkSynchronizeSucceeded Status: True Type: WorkSynchronized Last Transition Time: 2024-04-01T18:55:36Z Message: Successfully applied resources Observed Generation: 2 Reason: ApplySucceeded Status: True Type: ResourceApplied Selected Resources: Kind: Namespace Name: my-namespace Version: v1 Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal PlacementScheduleSuccess 108s cluster-resource-placement-controller Successfully scheduled the placement Normal PlacementSyncSuccess 103s cluster-resource-placement-controller Successfully synchronized the placement Normal PlacementRolloutCompleted 103s cluster-resource-placement-controller Resources have been applied to the selected clusters
清理资源
如果不再需要使用 ClusterResourcePlacement
对象,可以使用 kubectl delete
命令将其删除。 以下示例删除名为 crp
的 ClusterResourcePlacement
对象:
kubectl delete clusterresourceplacement crp
后续步骤
若要了解有关资源传播的详细信息,请参阅以下资源: