將資源從 Azure Kubernetes Fleet Manager (Fleet) 中樞叢集傳播至成員叢集
本文提供如何將資源從 Azure Kubernetes Fleet Manager(Fleet) 中樞叢集傳播至成員叢集的概觀。
必要條件
如果您沒有 Azure 訂用帳戶,請在開始之前先建立 Azure 免費帳戶。
- 請閱讀資源傳播概念概觀,以瞭解本快速入門中使用的概念和術語。
- 具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶。
- 您需要具有中樞叢集和成員叢集的機群資源。 如果您沒有 Fleet 資源,請參閱使用 Azure CLI 建立 Azure Kubernetes 機群管理員資源並加入成員叢集。
- 成員叢集必須在中樞叢集中適當標示,以符合所需的選取準則。 範例標籤包括區域、環境、小組、可用性區域、節點可用性,或所需的任何其他項目。
- 您需要存取中樞叢集的 Kubernetes API。 如果您沒有存取權,請參閱 Access Fleet 中樞叢集 Kubernetes API。
使用 ClusterResourcePlacement
API 將資源傳播至成員叢集
ClusterResourcePlacement
API 物件可用於將資源從中樞叢集傳播至成員叢集。 ClusterResourcePlacement
API 物件會指定要傳播的資源,以及選取成員叢集時要使用的放置原則。 ClusterResourcePlacement
API 物件會在中樞叢集中建立,並用於將資源傳播至成員叢集。 此範例示範如何使用具有 PickAll
放置原則的 ClusterResourcePlacement
API 物件,將命名空間傳播至成員叢集。
如需詳細資訊,請參閱 Kubernetes 資源從中樞叢集傳播到成員叢集 和 開放原始碼 Fleet 檔。
使用
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/v1 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/v1 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
下一步
若要深入了解資源傳播,請參閱下列資源: