Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article describes how to use Azure Kubernetes Fleet Manager (Kubernetes Fleet) cluster resource placement to deploy workloads across clusters in a fleet.
Prerequisites
- If you don't have an Azure trail subscription, create a trial subscription before you begin.
- Read the conceptual overview of resource propagation to understand the concepts and terminology used in this article.
- You need a Kubernetes Fleet resource with a hub cluster and member clusters. If you don't have one, see Create an Azure Kubernetes Fleet Manager resource and join member clusters by using the Azure CLI.
- Member clusters must be labeled appropriately in the hub cluster to match the desired selection criteria. Example labels include region, environment, team, availability zones, node availability, or anything else that you want.
- You need access to the Kubernetes API of the hub cluster. If you don't have access, see Access the Kubernetes API for an Azure Kubernetes Fleet Manager hub cluster.
Use ClusterResourcePlacement to place resources onto member clusters
The ClusterResourcePlacement
object is created on the hub cluster and is used to propagate resources to member clusters. It specifies the resources to propagate and the placement policy to use when you're selecting member clusters. This example demonstrates how to propagate a namespace to member clusters by using the ClusterResourcePlacement
object with a PickAll
placement policy.
For more information, see resource placement using Azure Kubernetes Fleet Manager cluster resource placement and the open-source Kubernetes Fleet documentation.
- Create a namespace to place onto the member clusters:
kubectl create namespace my-namespace
- Create a
ClusterResourcePlacement
object and apply to the Kubernetes Fleet hub cluster. In the following example, aClusterResourcePlacement
nameddistribute-my-namespace
is used to deploy a namespacemy-namespace
to all member clusters by usingPickAll
placement policy:
apiVersion: placement.kubernetes-fleet.io/v1
kind: ClusterResourcePlacement
metadata:
name: distribute-my-namespace
spec:
resourceSelectors:
- group: ""
kind: Namespace
version: v1
name: my-namespace
policy:
placementType: PickAll
Apply this to the Kubernetes Fleet hub cluster by issuing kubectl apply -f distribute-my-namespace.yaml
, using the name of the file you created in place of distribute-my-namespace.yaml
.
- Check the progress of the resource propagation:
kubectl get clusterresourceplacement distribute-my-namespace
Your output should look similar to the following example:
NAME GEN SCHEDULED SCHEDULEDGEN APPLIED APPLIEDGEN AGE
distribute-my-namespace 2 True 2 True 2 10s
- View the details of the placement object:
kubectl describe clusterresourceplacement distribute-my-namespace
Your output should look similar to the following example:
Name: distribute-my-namespace
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
Clean up resources
If you no longer want to use the ClusterResourcePlacement
object, you can delete it by using the kubectl delete
command. The following example deletes the ClusterResourcePlacement
object named distribute-my-namespace
:
kubectl delete clusterresourceplacement distribute-my-namespace
Related content
To learn more about resource propagation, see the following resources: