|
| 1 | +--- |
| 2 | +title: "Use taints on member clusters and tolerations on cluster resource placements in Azure Kubernetes Fleet Manager" |
| 3 | +description: Learn how to use taints on `MemberCluster` resources and tolerations on `ClusterResourcePlacement` resources in Azure Kubernetes Fleet Manager. |
| 4 | +ms.topic: how-to |
| 5 | +ms.date: 04/23/2024 |
| 6 | +author: schaffererin |
| 7 | +ms.author: schaffererin |
| 8 | +ms.service: kubernetes-fleet |
| 9 | +--- |
| 10 | + |
| 11 | +# Use taints on member clusters and tolerations on cluster resource placements |
| 12 | + |
| 13 | +This article explains how to add/remove taints on `MemberCluster` resources and tolerations on `ClusterResourcePlacement` resources in Azure Kubernetes Fleet Manager. |
| 14 | + |
| 15 | +Taints and tolerations work together to ensure member clusters only receive specified resources during resource propagation. Taints are applied to `MemberCluster` resources to prevent resources from being propagated to the member cluster. Tolerations are applied to `ClusterResourcePlacement` resources to allow resources to be propagated to the member cluster, even if the member cluster has a taint. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +* [!INCLUDE [free trial note](../../includes/quickstarts-free-trial-note.md)] |
| 20 | +* Read the conceptual overviews for [taints](./concepts-fleet.md#taints) and [tolerations](./concepts-resource-propagation.md#tolerations). |
| 21 | +* You must have a Fleet resource with a hub cluster and member clusters. If you don't have this resource, follow [Quickstart: Create a Fleet resource and join member clusters](quickstart-create-fleet-and-members.md). |
| 22 | +* You must gain access to the Kubernetes API of the hub cluster by following the steps in [Access the Kubernetes API of the Fleet resource](./quickstart-access-fleet-kubernetes-api.md). |
| 23 | + |
| 24 | +## Add taints to a member cluster |
| 25 | + |
| 26 | +In this example, we add a taint to a `MemberCluster` resource, then try to propagate resources to the member cluster using a `ClusterResourcePlacement` with a `PickAll` placement policy. The resources shouldn't be propagated to the member cluster because of the taint. |
| 27 | + |
| 28 | +1. Create a namespace to propagate to the member cluster using the `kubectl create ns` command. |
| 29 | + |
| 30 | + ```bash |
| 31 | + kubectl create ns test-ns |
| 32 | + ``` |
| 33 | + |
| 34 | +2. Create a taint on the `MemberCluster` resource using the following example code: |
| 35 | + |
| 36 | + ```yml |
| 37 | + apiVersion: cluster.kubernetes-fleet.io/v1beta1 |
| 38 | + kind: MemberCluster |
| 39 | + metadata: |
| 40 | + name: kind-cluster-1 |
| 41 | + spec: |
| 42 | + identity: |
| 43 | + name: fleet-member-agent-cluster-1 |
| 44 | + kind: ServiceAccount |
| 45 | + namespace: fleet-system |
| 46 | + apiGroup: "" |
| 47 | + taints: # Add taint to the member cluster |
| 48 | + - key: test-key1 |
| 49 | + value: test-value1 |
| 50 | + effect: NoSchedule |
| 51 | + ``` |
| 52 | + |
| 53 | +3. Apply the taint to the `MemberCluster` resource using the `kubectl apply` command. Make sure you replace the file name with the name of your file. |
| 54 | + |
| 55 | + ```bash |
| 56 | + kubectl apply -f member-cluster-taint.yml |
| 57 | + ``` |
| 58 | + |
| 59 | +4. Create a `PickAll` placement policy on the `ClusterResourcePlacement` resource using the following example code: |
| 60 | + |
| 61 | + ```yml |
| 62 | + resourceSelectors: |
| 63 | + - group: "" |
| 64 | + kind: Namespace |
| 65 | + version: v1 |
| 66 | + name: test-ns |
| 67 | + policy: |
| 68 | + placementType: PickAll |
| 69 | + ``` |
| 70 | + |
| 71 | +5. Apply the `ClusterResourcePlacement` resource using the `kubectl apply` command. Make sure you replace the file name with the name of your file. |
| 72 | + |
| 73 | + ```bash |
| 74 | + kubectl apply -f cluster-resource-placement-pick-all.yml |
| 75 | + ``` |
| 76 | + |
| 77 | +6. Verify that the resources weren't propagated to the member cluster by checking the details of the `ClusterResourcePlacement` resource using the `kubectl describe` command. |
| 78 | +
|
| 79 | + ```bash |
| 80 | + kubectl describe clusterresourceplacement test-ns |
| 81 | + ``` |
| 82 | +
|
| 83 | + Your output should look similar to the following example output: |
| 84 | +
|
| 85 | + ```output |
| 86 | + status: |
| 87 | + conditions: |
| 88 | + - lastTransitionTime: "2024-04-16T19:03:17Z" |
| 89 | + message: found all the clusters needed as specified by the scheduling policy |
| 90 | + observedGeneration: 2 |
| 91 | + reason: SchedulingPolicyFulfilled |
| 92 | + status: "True" |
| 93 | + type: ClusterResourcePlacementScheduled |
| 94 | + - lastTransitionTime: "2024-04-16T19:03:17Z" |
| 95 | + message: All 0 cluster(s) are synchronized to the latest resources on the hub |
| 96 | + cluster |
| 97 | + observedGeneration: 2 |
| 98 | + reason: SynchronizeSucceeded |
| 99 | + status: "True" |
| 100 | + type: ClusterResourcePlacementSynchronized |
| 101 | + - lastTransitionTime: "2024-04-16T19:03:17Z" |
| 102 | + message: There are no clusters selected to place the resources |
| 103 | + observedGeneration: 2 |
| 104 | + reason: ApplySucceeded |
| 105 | + status: "True" |
| 106 | + type: ClusterResourcePlacementApplied |
| 107 | + observedResourceIndex: "0" |
| 108 | + selectedResources: |
| 109 | + - kind: Namespace |
| 110 | + name: test-ns |
| 111 | + version: v1 |
| 112 | + ``` |
| 113 | +
|
| 114 | +## Remove taints from a member cluster |
| 115 | +
|
| 116 | +In this example, we remove the taint we created in [add taints to a member cluster](#add-taints-to-a-member-cluster). This should automatically trigger the Fleet scheduler to propagate the resources to the member cluster. |
| 117 | +
|
| 118 | +1. Open your `MemberCluster` YAML file and remove the taint section. |
| 119 | +2. Apply the changes to the `MemberCluster` resource using the `kubectl apply` command. Make sure you replace the file name with the name of your file. |
| 120 | +
|
| 121 | + ```bash |
| 122 | + kubectl apply -f member-cluster-taint.yml |
| 123 | + ``` |
| 124 | +
|
| 125 | +3. Verify that the resources were propagated to the member cluster by checking the details of the `ClusterResourcePlacement` resource using the `kubectl describe` command. |
| 126 | +
|
| 127 | + ```bash |
| 128 | + kubectl describe clusterresourceplacement test-ns |
| 129 | + ``` |
| 130 | +
|
| 131 | + Your output should look similar to the following example output: |
| 132 | +
|
| 133 | + ```output |
| 134 | + status: |
| 135 | + conditions: |
| 136 | + - lastTransitionTime: "2024-04-16T20:00:03Z" |
| 137 | + message: found all the clusters needed as specified by the scheduling policy |
| 138 | + observedGeneration: 2 |
| 139 | + reason: SchedulingPolicyFulfilled |
| 140 | + status: "True" |
| 141 | + type: ClusterResourcePlacementScheduled |
| 142 | + - lastTransitionTime: "2024-04-16T20:02:57Z" |
| 143 | + message: All 1 cluster(s) are synchronized to the latest resources on the hub |
| 144 | + cluster |
| 145 | + observedGeneration: 2 |
| 146 | + reason: SynchronizeSucceeded |
| 147 | + status: "True" |
| 148 | + type: ClusterResourcePlacementSynchronized |
| 149 | + - lastTransitionTime: "2024-04-16T20:02:57Z" |
| 150 | + message: Successfully applied resources to 1 member clusters |
| 151 | + observedGeneration: 2 |
| 152 | + reason: ApplySucceeded |
| 153 | + status: "True" |
| 154 | + type: ClusterResourcePlacementApplied |
| 155 | + observedResourceIndex: "0" |
| 156 | + placementStatuses: |
| 157 | + - clusterName: kind-cluster-1 |
| 158 | + conditions: |
| 159 | + - lastTransitionTime: "2024-04-16T20:02:52Z" |
| 160 | + message: 'Successfully scheduled resources for placement in kind-cluster-1 (affinity |
| 161 | + score: 0, topology spread score: 0): picked by scheduling policy' |
| 162 | + observedGeneration: 2 |
| 163 | + reason: ScheduleSucceeded |
| 164 | + status: "True" |
| 165 | + type: Scheduled |
| 166 | + - lastTransitionTime: "2024-04-16T20:02:57Z" |
| 167 | + message: Successfully Synchronized work(s) for placement |
| 168 | + observedGeneration: 2 |
| 169 | + reason: WorkSynchronizeSucceeded |
| 170 | + status: "True" |
| 171 | + type: WorkSynchronized |
| 172 | + - lastTransitionTime: "2024-04-16T20:02:57Z" |
| 173 | + message: Successfully applied resources |
| 174 | + observedGeneration: 2 |
| 175 | + reason: ApplySucceeded |
| 176 | + status: "True" |
| 177 | + type: Applied |
| 178 | + selectedResources: |
| 179 | + - kind: Namespace |
| 180 | + name: test-ns |
| 181 | + version: v1 |
| 182 | + ``` |
| 183 | +
|
| 184 | +## Add tolerations to a cluster resource placement |
| 185 | +
|
| 186 | +In this example, we add a toleration to a `ClusterResourcePlacement` resource to propagate resources to a member cluster that has a taint. The toleration allows the resources to be propagated to the member cluster. |
| 187 | +
|
| 188 | +1. Create a namespace to propagate to the member cluster using the `kubectl create ns` command. |
| 189 | +
|
| 190 | + ```bash |
| 191 | + kubectl create ns test-ns |
| 192 | + ``` |
| 193 | +
|
| 194 | +2. Create a taint on the `MemberCluster` resource using the following example code: |
| 195 | +
|
| 196 | + ```yml |
| 197 | + apiVersion: cluster.kubernetes-fleet.io/v1beta1 |
| 198 | + kind: MemberCluster |
| 199 | + metadata: |
| 200 | + name: kind-cluster-1 |
| 201 | + spec: |
| 202 | + identity: |
| 203 | + name: fleet-member-agent-cluster-1 |
| 204 | + kind: ServiceAccount |
| 205 | + namespace: fleet-system |
| 206 | + apiGroup: "" |
| 207 | + taints: # Add taint to the member cluster |
| 208 | + - key: test-key1 |
| 209 | + value: test-value1 |
| 210 | + effect: NoSchedule |
| 211 | + ``` |
| 212 | + |
| 213 | +3. Apply the taint to the `MemberCluster` resource using the `kubectl apply` command. Make sure you replace the file name with the name of your file. |
| 214 | +
|
| 215 | + ```bash |
| 216 | + kubectl apply -f member-cluster-taint.yml |
| 217 | + ``` |
| 218 | +
|
| 219 | +4. Create a toleration on the `ClusterResourcePlacement` resource using the following example code: |
| 220 | +
|
| 221 | + ```yml |
| 222 | + spec: |
| 223 | + policy: |
| 224 | + placementType: PickAll |
| 225 | + tolerations: |
| 226 | + - key: test-key1 |
| 227 | + operator: Exists |
| 228 | + resourceSelectors: |
| 229 | + - group: "" |
| 230 | + kind: Namespace |
| 231 | + name: test-ns |
| 232 | + version: v1 |
| 233 | + revisionHistoryLimit: 10 |
| 234 | + strategy: |
| 235 | + type: RollingUpdate |
| 236 | + ``` |
| 237 | +
|
| 238 | +5. Apply the `ClusterResourcePlacement` resource using the `kubectl apply` command. Make sure you replace the file name with the name of your file. |
| 239 | +
|
| 240 | + ```bash |
| 241 | + kubectl apply -f cluster-resource-placement-toleration.yml |
| 242 | + ``` |
| 243 | +
|
| 244 | +6. Verify that the resources were propagated to the member cluster by checking the details of the `ClusterResourcePlacement` resource using the `kubectl describe` command. |
| 245 | +
|
| 246 | + ```bash |
| 247 | + kubectl describe clusterresourceplacement test-ns |
| 248 | + ``` |
| 249 | +
|
| 250 | + Your output should look similar to the following example output: |
| 251 | +
|
| 252 | + ```output |
| 253 | + status: |
| 254 | + conditions: |
| 255 | + - lastTransitionTime: "2024-04-16T20:16:10Z" |
| 256 | + message: found all the clusters needed as specified by the scheduling policy |
| 257 | + observedGeneration: 3 |
| 258 | + reason: SchedulingPolicyFulfilled |
| 259 | + status: "True" |
| 260 | + type: ClusterResourcePlacementScheduled |
| 261 | + - lastTransitionTime: "2024-04-16T20:16:15Z" |
| 262 | + message: All 1 cluster(s) are synchronized to the latest resources on the hub |
| 263 | + cluster |
| 264 | + observedGeneration: 3 |
| 265 | + reason: SynchronizeSucceeded |
| 266 | + status: "True" |
| 267 | + type: ClusterResourcePlacementSynchronized |
| 268 | + - lastTransitionTime: "2024-04-16T20:16:15Z" |
| 269 | + message: Successfully applied resources to 1 member clusters |
| 270 | + observedGeneration: 3 |
| 271 | + reason: ApplySucceeded |
| 272 | + status: "True" |
| 273 | + type: ClusterResourcePlacementApplied |
| 274 | + observedResourceIndex: "0" |
| 275 | + placementStatuses: |
| 276 | + - clusterName: kind-cluster-1 |
| 277 | + conditions: |
| 278 | + - lastTransitionTime: "2024-04-16T20:16:10Z" |
| 279 | + message: 'Successfully scheduled resources for placement in kind-cluster-1 (affinity |
| 280 | + score: 0, topology spread score: 0): picked by scheduling policy' |
| 281 | + observedGeneration: 3 |
| 282 | + reason: ScheduleSucceeded |
| 283 | + status: "True" |
| 284 | + type: Scheduled |
| 285 | + - lastTransitionTime: "2024-04-16T20:16:15Z" |
| 286 | + message: Successfully Synchronized work(s) for placement |
| 287 | + observedGeneration: 3 |
| 288 | + reason: WorkSynchronizeSucceeded |
| 289 | + status: "True" |
| 290 | + type: WorkSynchronized |
| 291 | + - lastTransitionTime: "2024-04-16T20:16:15Z" |
| 292 | + message: Successfully applied resources |
| 293 | + observedGeneration: 3 |
| 294 | + reason: ApplySucceeded |
| 295 | + status: "True" |
| 296 | + type: Applied |
| 297 | + selectedResources: |
| 298 | + - kind: Namespace |
| 299 | + name: test-ns |
| 300 | + version: v1 |
| 301 | + ``` |
| 302 | +
|
| 303 | +## Next steps |
| 304 | +
|
| 305 | +For more information on Azure Kubernetes Fleet Manager, see the [upstream Fleet documentation](https://github.com/Azure/fleet/tree/main/docs). |
0 commit comments