From f21fb61a11ce4f09b465e5562e5f5fac46ce93b1 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Thu, 25 Jul 2024 16:33:32 -0700 Subject: [PATCH 1/3] add tutorials --- docs/tutorials/MigrationWithOverrideDR.md | 490 ++++++++++++++++++++++ docs/tutorials/README.md | 24 +- docs/tutorials/RegionMigrationDR.md | 423 +++++++++++++++++++ 3 files changed, 936 insertions(+), 1 deletion(-) create mode 100644 docs/tutorials/MigrationWithOverrideDR.md create mode 100644 docs/tutorials/RegionMigrationDR.md diff --git a/docs/tutorials/MigrationWithOverrideDR.md b/docs/tutorials/MigrationWithOverrideDR.md new file mode 100644 index 000000000..e43fd9a5c --- /dev/null +++ b/docs/tutorials/MigrationWithOverrideDR.md @@ -0,0 +1,490 @@ +# Tutorial: Migrating Application Resources to Clusters with More Availability +This tutorial shows how to migrate applications from clusters with lower availability to those with higher availability, +while also scaling up the number of replicas, using Fleet. + +## Scenario +Your fleet consists of the following clusters: + +1. Member Cluster 1 & Member Cluster 2 (WestUS, 1 node each) +2. Member Cluster 3 (EastUS2, 2 nodes) +3. Member Cluster 4 & Member Cluster 5 (WestEurope, 3 nodes each) + +Due to a sudden increase in traffic and resource demands in your WestUS clusters, you need to migrate your applications to clusters in EastUS2 or WestEurope that have higher availability and can better handle the increased load. + +## Current Application Resources +The following resources are currently deployed in the WestUS clusters: + +#### Service +```yaml +apiVersion: v1 +kind: Service +metadata: + name: nginx-service + namespace: test-app +spec: + selector: + app: nginx + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer +``` +Summary: +- This defines a Kubernetes Service named `nginx-svc` in the `test-app` namespace. +- The service is of type LoadBalancer, meaning it exposes the application to the internet. +- It targets pods with the label app: nginx and forwards traffic to port 80 on the pods. + +#### Deployment +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + namespace: test-app +spec: + selector: + matchLabels: + app: nginx + replicas: 2 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.16.1 + ports: + - containerPort: 80 +``` +> Note: The current deployment has 2 replicas. + +Summary: +- This defines a Kubernetes Deployment named `nginx-deployment` in the `test-app` namespace. +- It creates 2 replicas of the nginx pod, each running the `nginx:1.16.1` image. +- The deployment ensures that the specified number of pods (replicas) are running and available. +- The pods are labeled with `app: nginx` and expose port 80. + +#### ClusterResourcePlacement +```yaml +apiVersion: placement.kubernetes-fleet.io/v1 +kind: ClusterResourcePlacement +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"placement.kubernetes-fleet.io/v1","kind":"ClusterResourcePlacement","metadata":{"annotations":{},"name":"crp-availability"},"spec":{"policy":{"affinity":{"clusterAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"clusterSelectorTerms":[{"labelSelector":{"matchLabels":{"fleet.azure.com/location":"westus"}}}]}}},"numberOfClusters":2,"placementType":"PickN"},"resourceSelectors":[{"group":"","kind":"Namespace","name":"test-app","version":"v1"}],"revisionHistoryLimit":10,"strategy":{"type":"RollingUpdate"}}} + creationTimestamp: "2024-07-25T23:00:53Z" + finalizers: + - kubernetes-fleet.io/crp-cleanup + - kubernetes-fleet.io/scheduler-cleanup + generation: 1 + name: crp-availability + resourceVersion: "22228766" + uid: 58dbb5d1-4afa-479f-bf57-413328aa61bd +spec: + policy: + affinity: + clusterAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + clusterSelectorTerms: + - labelSelector: + matchLabels: + fleet.azure.com/location: westus + numberOfClusters: 2 + placementType: PickN + resourceSelectors: + - group: "" + kind: Namespace + name: test-app + version: v1 + revisionHistoryLimit: 10 + strategy: + type: RollingUpdate +status: + conditions: + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: found all cluster needed as specified by the scheduling policy, found + 2 cluster(s) + observedGeneration: 1 + reason: SchedulingPolicyFulfilled + status: "True" + type: ClusterResourcePlacementScheduled + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: All 2 cluster(s) start rolling out the latest resource + observedGeneration: 1 + reason: RolloutStarted + status: "True" + type: ClusterResourcePlacementRolloutStarted + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: No override rules are configured for the selected resources + observedGeneration: 1 + reason: NoOverrideSpecified + status: "True" + type: ClusterResourcePlacementOverridden + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: Works(s) are succcesfully created or updated in 2 target cluster(s)' + namespaces + observedGeneration: 1 + reason: WorkSynchronized + status: "True" + type: ClusterResourcePlacementWorkSynchronized + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: The selected resources are successfully applied to 2 cluster(s) + observedGeneration: 1 + reason: ApplySucceeded + status: "True" + type: ClusterResourcePlacementApplied + - lastTransitionTime: "2024-07-25T23:01:02Z" + message: The selected resources in 2 cluster(s) are available now + observedGeneration: 1 + reason: ResourceAvailable + status: "True" + type: ClusterResourcePlacementAvailable + observedResourceIndex: "0" + placementStatuses: + - clusterName: aks-member-2 + conditions: + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: 'Successfully scheduled resources for placement in "aks-member-2" + (affinity score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 1 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 1 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: No override rules are configured for the selected resources + observedGeneration: 1 + reason: NoOverrideSpecified + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: All of the works are synchronized to the latest + observedGeneration: 1 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: All corresponding work objects are applied + observedGeneration: 1 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T23:01:02Z" + message: All corresponding work objects are available + observedGeneration: 1 + reason: AllWorkAreAvailable + status: "True" + type: Available + - clusterName: aks-member-1 + conditions: + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: 'Successfully scheduled resources for placement in "aks-member-1" + (affinity score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 1 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 1 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: No override rules are configured for the selected resources + observedGeneration: 1 + reason: NoOverrideSpecified + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: All of the works are synchronized to the latest + observedGeneration: 1 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T23:00:53Z" + message: All corresponding work objects are applied + observedGeneration: 1 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T23:01:02Z" + message: All corresponding work objects are available + observedGeneration: 1 + reason: AllWorkAreAvailable + status: "True" + type: Available + selectedResources: + - kind: Namespace + name: test-app + version: v1 + - group: apps + kind: Deployment + name: nginx-deployment + namespace: test-app + version: v1 + - kind: Service + name: nginx-service + namespace: test-app + version: v1 +``` +Summary: +- This defines a ClusterResourcePlacement named `crp-availability`. +- The placement policy PickN selects 2 clusters. The clusters are selected based on the label `fleet.azure.com/location: westus`. +- It targets resources in the `test-app` namespace. + +### Identify Clusters with More Availability +To identify clusters with more availability, you can check the member cluster properties. +```bash +kubectl get memberclusters -A -o wide +``` +The output will show the availability in each cluster, including the number of nodes, available CPU, and memory. +```bash +NAME JOINED AGE NODE-COUNT AVAILABLE-CPU AVAILABLE-MEMORY ALLOCATABLE-CPU ALLOCATABLE-MEMORY +aks-member-1 True 22d 1 30m 40Ki 1900m 4652296Ki +aks-member-2 True 22d 1 30m 40Ki 1900m 4652296Ki +aks-member-3 True 22d 2 2820m 8477196Ki 3800m 9304588Ki +aks-member-4 True 22d 3 4408m 12896012Ki 5700m 13956876Ki +aks-member-5 True 22d 3 4408m 12896024Ki 5700m 13956888Ki +``` +Based on the available resources, you can see that Member Cluster 3 in EastUS2 and Member Cluster 4 & 5 in WestEurope have more nodes and available resources compared to the WestUS clusters. + +## Migrating Applications to a Different Cluster with More Availability While Scaling Up +When the clusters in WestUS are nearing capacity limits and risk becoming overloaded, update the ClusterResourcePlacement (CRP) to migrate the applications to clusters in EastUS2 or WestEurope, which have more available resources and can handle increased demand more effectively. +For this tutorial, we will move them to WestEurope. + +## Create Resource Override +To scale up during migration, apply this override before updating crp: +```yaml +apiVersion: placement.kubernetes-fleet.io/v1alpha1 +kind: ResourceOverride +metadata: + name: ro-1 + namespace: test-app +spec: + resourceSelectors: + - group: apps + kind: Deployment + version: v1 + name: nginx-deployment + policy: + overrideRules: + - clusterSelector: + clusterSelectorTerms: + - labelSelector: + matchLabels: + fleet.azure.com/location: westeurope + jsonPatchOverrides: + - op: replace + path: /spec/replicas + value: + 4 +``` +This override updates the `nginx-deployment` Deployment in the `test-app` namespace by setting the number of replicas to "4" for clusters located in the westeurope region. + +#### Update the CRP for Migration +```yaml +apiVersion: placement.kubernetes-fleet.io/v1 +kind: ClusterResourcePlacement +metadata: + name: crp-availability +spec: + policy: + placementType: PickN + numberOfClusters: 2 + affinity: + clusterAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + clusterSelectorTerms: + - propertySelector: + matchExpressions: + - name: kubernetes-fleet.io/node-count + operator: Ge + values: + - "3" + resourceSelectors: + - group: "" + kind: Namespace + name: test-app + version: v1 + revisionHistoryLimit: 10 + strategy: + type: RollingUpdate +``` +Update the `crp.yaml` to reflect selecting clusters with higher node-count and apply it: +```bash +kubectl apply -f crp.yaml +``` + +### Results +After applying the updated `crp.yaml`, the Fleet will schedule the application on the available clusters in WestEurope as they each have 3 nodes. +You can check the status of the CRP to ensure that the application has been successfully migrated and is running in the new region: +```bash +kubectl get crp crp-availability -o yaml +``` +You should see a status indicating that the application is now running in the WestEurope clusters, similar to the following: +#### CRP Status +```yaml +... +status: + conditions: + - lastTransitionTime: "2024-07-25T23:10:08Z" + message: found all cluster needed as specified by the scheduling policy, found + 2 cluster(s) + observedGeneration: 2 + reason: SchedulingPolicyFulfilled + status: "True" + type: ClusterResourcePlacementScheduled + - lastTransitionTime: "2024-07-25T23:10:20Z" + message: All 2 cluster(s) start rolling out the latest resource + observedGeneration: 2 + reason: RolloutStarted + status: "True" + type: ClusterResourcePlacementRolloutStarted + - lastTransitionTime: "2024-07-25T23:10:20Z" + message: The selected resources are successfully overridden in 2 cluster(s) + observedGeneration: 2 + reason: OverriddenSucceeded + status: "True" + type: ClusterResourcePlacementOverridden + - lastTransitionTime: "2024-07-25T23:10:20Z" + message: Works(s) are succcesfully created or updated in 2 target cluster(s)' + namespaces + observedGeneration: 2 + reason: WorkSynchronized + status: "True" + type: ClusterResourcePlacementWorkSynchronized + - lastTransitionTime: "2024-07-25T23:10:21Z" + message: The selected resources are successfully applied to 2 cluster(s) + observedGeneration: 2 + reason: ApplySucceeded + status: "True" + type: ClusterResourcePlacementApplied + - lastTransitionTime: "2024-07-25T23:10:30Z" + message: The selected resources in 2 cluster(s) are available now + observedGeneration: 2 + reason: ResourceAvailable + status: "True" + type: ClusterResourcePlacementAvailable + observedResourceIndex: "0" + placementStatuses: + - applicableResourceOverrides: + - name: ro-1-0 + namespace: test-app + clusterName: aks-member-5 + conditions: + - lastTransitionTime: "2024-07-25T23:10:08Z" + message: 'Successfully scheduled resources for placement in "aks-member-5" (affinity + score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 2 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T23:10:20Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 2 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T23:10:20Z" + message: Successfully applied the override rules on the resources + observedGeneration: 2 + reason: OverriddenSucceeded + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T23:10:20Z" + message: All of the works are synchronized to the latest + observedGeneration: 2 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T23:10:21Z" + message: All corresponding work objects are applied + observedGeneration: 2 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T23:10:30Z" + message: All corresponding work objects are available + observedGeneration: 2 + reason: AllWorkAreAvailable + status: "True" + type: Available + - applicableResourceOverrides: + - name: ro-1-0 + namespace: test-app + clusterName: aks-member-4 + conditions: + - lastTransitionTime: "2024-07-25T23:10:08Z" + message: 'Successfully scheduled resources for placement in "aks-member-4" (affinity + score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 2 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T23:10:08Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 2 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T23:10:08Z" + message: Successfully applied the override rules on the resources + observedGeneration: 2 + reason: OverriddenSucceeded + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T23:10:08Z" + message: All of the works are synchronized to the latest + observedGeneration: 2 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T23:10:09Z" + message: All corresponding work objects are applied + observedGeneration: 2 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T23:10:19Z" + message: All corresponding work objects are available + observedGeneration: 2 + reason: AllWorkAreAvailable + status: "True" + type: Available + selectedResources: + - kind: Namespace + name: test-app + version: v1 + - group: apps + kind: Deployment + name: nginx-deployment + namespace: test-app + version: v1 + - kind: Service + name: nginx-service + namespace: test-app + version: v1 +``` +The status indicates that the application has been successfully migrated to the WestEurope clusters and is now running with 4 replicas, as the resource override has been applied. + +To double-check, you can also verify the number of replicas in the `nginx-deployment`: +1. Change context to member cluster 4 or 5: + ```bash + kubectl config use-context aks-member-4 + ``` +2. Get the deployment: + ```bash + kubectl get deployment nginx-deployment -n test-app -o wide + ``` + +## Conclusion +This tutorial demonstrated how to migrate applications using Fleet from clusters with lower availability to those with higher availability. +By updating the ClusterResourcePlacement and applying a ResourceOverride, you can ensure that your applications are moved to clusters with better availability while also scaling up the number of replicas to enhance performance and resilience. \ No newline at end of file diff --git a/docs/tutorials/README.md b/docs/tutorials/README.md index ed3e5187d..50019d78f 100644 --- a/docs/tutorials/README.md +++ b/docs/tutorials/README.md @@ -1 +1,23 @@ -TBA. \ No newline at end of file +# Fleet Tutorials + +Welcome to the Fleet Tutorials! This guide will help you understand how Fleet can seamlessly integrate with your development and operations workflows. +Follow the instructions provided to get the most out of Fleet's features. + +> Note +> +> If you are just getting started with Fleet, it is recommended that you refer to the +> [Fleet Getting Started Guide](../../README.md) for how to create a fleet and [Fleet Concepts](../concepts/README.md) +> for an overview of Fleet features and capabilities. + + +Below is a walkthrough of all the how-to guides currently available: +* [Migrating Applications to Another Region When a Region Goes Down ](RegionMigrationDR.md) + + This tutorial guides you through migrating application resources across regions using Fleet. + If a region experiences an outage, you can update the `ClusterResourcePlacement` (CRP) to redeploy your Kubernetes Service + and Deployment in another region, ensuring continued availability and resilience. + +* [Migrating Application Resources to Clusters with More Availability](MigrationWithOverrideDR.md) + + This tutorial will guide you through migrating your application resources to clusters with higher availability using Fleet. + This process not only ensures your application is deployed in clusters with better resource availability but also scales up the number of replicas to enhance performance and reliability. \ No newline at end of file diff --git a/docs/tutorials/RegionMigrationDR.md b/docs/tutorials/RegionMigrationDR.md new file mode 100644 index 000000000..4eda87de3 --- /dev/null +++ b/docs/tutorials/RegionMigrationDR.md @@ -0,0 +1,423 @@ +# Tutorial: Migrating Applications to Another Region When a Region Goes Down +This tutorial demonstrates how to move applications from clusters in a region that have gone down to clusters in another region using AKS Fleet. + +## Scenario +Your fleet consists of the following clusters: + +1. Member Cluster 1 & Member Cluster 2 (WestUS, 1 node each) +2. Member Cluster 3 (EastUS2, 2 nodes) +3. Member Cluster 4 & Member Cluster 5 (WestEurope, 3 nodes each) + +Due to an outage in WestUS, you need to migrate your applications from the WestUS clusters to clusters in EastUS2 or WestEurope. + +## Current Application Resources +The following resources are currently deployed in the WestUS clusters: + +#### Service +```yaml +apiVersion: v1 +kind: Service +metadata: + name: nginx-service + namespace: test-app +spec: + selector: + app: nginx + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: LoadBalancer +``` +Summary: +- This defines a Kubernetes Service named `nginx-svc` in the `test-app` namespace. +- The service is of type LoadBalancer, meaning it exposes the application to the internet. +- It targets pods with the label app: nginx and forwards traffic to port 80 on the pods. + +#### Deployment +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + namespace: test-app +spec: + selector: + matchLabels: + app: nginx + replicas: 2 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.16.1 + ports: + - containerPort: 80 +``` +Summary: +- This defines a Kubernetes Deployment named `nginx-deployment` in the `test-app` namespace. +- It creates 2 replicas of the nginx pod, each running the `nginx:1.16.1` image. +- The deployment ensures that the specified number of pods (replicas) are running and available. +- The pods are labeled with `app: nginx` and expose port 80. + +#### ClusterResourcePlacement +```yaml +apiVersion: placement.kubernetes-fleet.io/v1 +kind: ClusterResourcePlacement +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"placement.kubernetes-fleet.io/v1","kind":"ClusterResourcePlacement","metadata":{"annotations":{},"name":"crp-migration"},"spec":{"policy":{"affinity":{"clusterAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"clusterSelectorTerms":[{"labelSelector":{"matchLabels":{"fleet.azure.com/location":"westus"}}}]}}},"numberOfClusters":2,"placementType":"PickN"},"resourceSelectors":[{"group":"","kind":"Namespace","name":"test-app","version":"v1"}],"revisionHistoryLimit":10,"strategy":{"type":"RollingUpdate"}}} + creationTimestamp: "2024-07-25T21:27:35Z" + finalizers: + - kubernetes-fleet.io/crp-cleanup + - kubernetes-fleet.io/scheduler-cleanup + generation: 1 + name: crp-migration + resourceVersion: "22177519" + uid: 0683cfaa-df24-4b2c-8a3d-07031692da8f +spec: + policy: + affinity: + clusterAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + clusterSelectorTerms: + - labelSelector: + matchLabels: + fleet.azure.com/location: westus + numberOfClusters: 2 + placementType: PickN + resourceSelectors: + - group: "" + kind: Namespace + name: test-app + version: v1 + revisionHistoryLimit: 10 + strategy: + type: RollingUpdate +status: + conditions: + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: found all cluster needed as specified by the scheduling policy, found + 2 cluster(s) + observedGeneration: 1 + reason: SchedulingPolicyFulfilled + status: "True" + type: ClusterResourcePlacementScheduled + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: All 2 cluster(s) start rolling out the latest resource + observedGeneration: 1 + reason: RolloutStarted + status: "True" + type: ClusterResourcePlacementRolloutStarted + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: No override rules are configured for the selected resources + observedGeneration: 1 + reason: NoOverrideSpecified + status: "True" + type: ClusterResourcePlacementOverridden + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: Works(s) are succcesfully created or updated in 2 target cluster(s)' + namespaces + observedGeneration: 1 + reason: WorkSynchronized + status: "True" + type: ClusterResourcePlacementWorkSynchronized + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: The selected resources are successfully applied to 2 cluster(s) + observedGeneration: 1 + reason: ApplySucceeded + status: "True" + type: ClusterResourcePlacementApplied + - lastTransitionTime: "2024-07-25T21:27:45Z" + message: The selected resources in 2 cluster(s) are available now + observedGeneration: 1 + reason: ResourceAvailable + status: "True" + type: ClusterResourcePlacementAvailable + observedResourceIndex: "0" + placementStatuses: + - clusterName: aks-member-2 + conditions: + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: 'Successfully scheduled resources for placement in "aks-member-2" + (affinity score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 1 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 1 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: No override rules are configured for the selected resources + observedGeneration: 1 + reason: NoOverrideSpecified + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: All of the works are synchronized to the latest + observedGeneration: 1 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: All corresponding work objects are applied + observedGeneration: 1 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T21:27:45Z" + message: All corresponding work objects are available + observedGeneration: 1 + reason: AllWorkAreAvailable + status: "True" + type: Available + - clusterName: aks-member-1 + conditions: + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: 'Successfully scheduled resources for placement in "aks-member-1" + (affinity score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 1 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 1 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: No override rules are configured for the selected resources + observedGeneration: 1 + reason: NoOverrideSpecified + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: All of the works are synchronized to the latest + observedGeneration: 1 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T21:27:35Z" + message: All corresponding work objects are applied + observedGeneration: 1 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T21:27:45Z" + message: All corresponding work objects are available + observedGeneration: 1 + reason: AllWorkAreAvailable + status: "True" + type: Available + selectedResources: + - kind: Namespace + name: test-app + version: v1 + - group: apps + kind: Deployment + name: nginx-deployment + namespace: test-app + version: v1 + - kind: Service + name: nginx-service + namespace: test-app + version: v1 +``` +Summary: +- This defines a ClusterResourcePlacement named `crp-migration`. +- The placement policy PickN selects 2 clusters. The clusters are selected based on the label `fleet.azure.com/location: westus`. +- It targets resources in the `test-app` namespace. + +## Migrating Applications to a Different Region +When the clusters in WestUS go down, update the ClusterResourcePlacement (CRP) to migrate the applications to another region. +For this tutorial, we will move them to WestEurope. + +#### Update the CRP for Migration to WestEurope +```yaml +apiVersion: placement.kubernetes-fleet.io/v1 +kind: ClusterResourcePlacement +metadata: + name: crp-migration +spec: + policy: + placementType: PickN + numberOfClusters: 2 + affinity: + clusterAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + clusterSelectorTerms: + - labelSelector: + matchLabels: + fleet.azure.com/location: westeurope # updated label + resourceSelectors: + - group: "" + kind: Namespace + name: test-app + version: v1 + revisionHistoryLimit: 10 + strategy: + type: RollingUpdate +``` +Update the `crp.yaml` to reflect the new region and apply it: +```bash +kubectl apply -f crp.yaml +``` + +### Results +After applying the updated `crp.yaml`, the Fleet will schedule the application on the available clusters in WestEurope. +You can check the status of the CRP to ensure that the application has been successfully migrated and is running in the new region: +```bash +kubectl get crp crp-migration -o yaml +``` +You should see a status indicating that the application is now running in the WestEurope clusters, similar to the following: +#### CRP Status +```yaml +... +status: + conditions: + - lastTransitionTime: "2024-07-25T21:36:02Z" + message: found all cluster needed as specified by the scheduling policy, found + 2 cluster(s) + observedGeneration: 2 + reason: SchedulingPolicyFulfilled + status: "True" + type: ClusterResourcePlacementScheduled + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: All 2 cluster(s) start rolling out the latest resource + observedGeneration: 2 + reason: RolloutStarted + status: "True" + type: ClusterResourcePlacementRolloutStarted + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: No override rules are configured for the selected resources + observedGeneration: 2 + reason: NoOverrideSpecified + status: "True" + type: ClusterResourcePlacementOverridden + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: Works(s) are succcesfully created or updated in 2 target cluster(s)' + namespaces + observedGeneration: 2 + reason: WorkSynchronized + status: "True" + type: ClusterResourcePlacementWorkSynchronized + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: The selected resources are successfully applied to 2 cluster(s) + observedGeneration: 2 + reason: ApplySucceeded + status: "True" + type: ClusterResourcePlacementApplied + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: The selected resources in 2 cluster(s) are available now + observedGeneration: 2 + reason: ResourceAvailable + status: "True" + type: ClusterResourcePlacementAvailable + observedResourceIndex: "0" + placementStatuses: + - clusterName: aks-member-5 + conditions: + - lastTransitionTime: "2024-07-25T21:36:02Z" + message: 'Successfully scheduled resources for placement in "aks-member-5" (affinity + score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 2 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 2 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: No override rules are configured for the selected resources + observedGeneration: 2 + reason: NoOverrideSpecified + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: All of the works are synchronized to the latest + observedGeneration: 2 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: All corresponding work objects are applied + observedGeneration: 2 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: All corresponding work objects are available + observedGeneration: 2 + reason: AllWorkAreAvailable + status: "True" + type: Available + - clusterName: aks-member-4 + conditions: + - lastTransitionTime: "2024-07-25T21:36:02Z" + message: 'Successfully scheduled resources for placement in "aks-member-4" (affinity + score: 0, topology spread score: 0): picked by scheduling policy' + observedGeneration: 2 + reason: Scheduled + status: "True" + type: Scheduled + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: Detected the new changes on the resources and started the rollout process + observedGeneration: 2 + reason: RolloutStarted + status: "True" + type: RolloutStarted + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: No override rules are configured for the selected resources + observedGeneration: 2 + reason: NoOverrideSpecified + status: "True" + type: Overridden + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: All of the works are synchronized to the latest + observedGeneration: 2 + reason: AllWorkSynced + status: "True" + type: WorkSynchronized + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: All corresponding work objects are applied + observedGeneration: 2 + reason: AllWorkHaveBeenApplied + status: "True" + type: Applied + - lastTransitionTime: "2024-07-25T21:36:14Z" + message: All corresponding work objects are available + observedGeneration: 2 + reason: AllWorkAreAvailable + status: "True" + type: Available + selectedResources: + - kind: Namespace + name: test-app + version: v1 + - group: apps + kind: Deployment + name: nginx-deployment + namespace: test-app + version: v1 + - kind: Service + name: nginx-service + namespace: test-app + version: v1 +``` + +## Conclusion +This tutorial demonstrated how to migrate applications using Fleet when clusters in one region go down. +By updating the ClusterResourcePlacement, you can ensure that your applications are moved to available clusters in another region, +maintaining availability and resilience. \ No newline at end of file From d6ad2bbe2893aa2e806f1c56b8c90934ed05d0a6 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Thu, 25 Jul 2024 16:52:26 -0700 Subject: [PATCH 2/3] address comment --- .../{RegionMigrationDR.md => ClusterMigrationDR.md} | 6 +++--- docs/tutorials/README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename docs/tutorials/{RegionMigrationDR.md => ClusterMigrationDR.md} (96%) diff --git a/docs/tutorials/RegionMigrationDR.md b/docs/tutorials/ClusterMigrationDR.md similarity index 96% rename from docs/tutorials/RegionMigrationDR.md rename to docs/tutorials/ClusterMigrationDR.md index 4eda87de3..adc1897ba 100644 --- a/docs/tutorials/RegionMigrationDR.md +++ b/docs/tutorials/ClusterMigrationDR.md @@ -1,4 +1,4 @@ -# Tutorial: Migrating Applications to Another Region When a Region Goes Down +# Tutorial: Migrating Applications to Another Cluster When a Cluster Goes Down This tutorial demonstrates how to move applications from clusters in a region that have gone down to clusters in another region using AKS Fleet. ## Scenario @@ -237,11 +237,11 @@ Summary: - The placement policy PickN selects 2 clusters. The clusters are selected based on the label `fleet.azure.com/location: westus`. - It targets resources in the `test-app` namespace. -## Migrating Applications to a Different Region +## Migrating Applications to a Cluster in a Different Region When the clusters in WestUS go down, update the ClusterResourcePlacement (CRP) to migrate the applications to another region. For this tutorial, we will move them to WestEurope. -#### Update the CRP for Migration to WestEurope +#### Update the CRP for Migration to WestEurope Cluster ```yaml apiVersion: placement.kubernetes-fleet.io/v1 kind: ClusterResourcePlacement diff --git a/docs/tutorials/README.md b/docs/tutorials/README.md index 50019d78f..8452e7a69 100644 --- a/docs/tutorials/README.md +++ b/docs/tutorials/README.md @@ -11,7 +11,7 @@ Follow the instructions provided to get the most out of Fleet's features. Below is a walkthrough of all the how-to guides currently available: -* [Migrating Applications to Another Region When a Region Goes Down ](RegionMigrationDR.md) +* [Migrating Applications to Another Cluster When a Cluster Goes Down ](ClusterMigrationDR.md) This tutorial guides you through migrating application resources across regions using Fleet. If a region experiences an outage, you can update the `ClusterResourcePlacement` (CRP) to redeploy your Kubernetes Service From 60484d7c162203cdf40973b60b92d83b80cb7d41 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Thu, 25 Jul 2024 18:50:30 -0700 Subject: [PATCH 3/3] update for clarification --- docs/tutorials/ClusterMigrationDR.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/tutorials/ClusterMigrationDR.md b/docs/tutorials/ClusterMigrationDR.md index adc1897ba..e3c9c0fa7 100644 --- a/docs/tutorials/ClusterMigrationDR.md +++ b/docs/tutorials/ClusterMigrationDR.md @@ -1,5 +1,5 @@ # Tutorial: Migrating Applications to Another Cluster When a Cluster Goes Down -This tutorial demonstrates how to move applications from clusters in a region that have gone down to clusters in another region using AKS Fleet. +This tutorial demonstrates how to move applications from clusters have gone down to other operational clusters using Fleet. ## Scenario Your fleet consists of the following clusters: @@ -8,10 +8,10 @@ Your fleet consists of the following clusters: 2. Member Cluster 3 (EastUS2, 2 nodes) 3. Member Cluster 4 & Member Cluster 5 (WestEurope, 3 nodes each) -Due to an outage in WestUS, you need to migrate your applications from the WestUS clusters to clusters in EastUS2 or WestEurope. +Due to certain circumstances, Member Cluster 1 and Member Cluster 2 are down, requiring you to migrate your applications from these clusters to other operational ones. ## Current Application Resources -The following resources are currently deployed in the WestUS clusters: +The following resources are currently deployed in Member Cluster 1 and Member Cluster 2 by the ClusterResourcePlacement: #### Service ```yaml @@ -234,14 +234,14 @@ status: ``` Summary: - This defines a ClusterResourcePlacement named `crp-migration`. -- The placement policy PickN selects 2 clusters. The clusters are selected based on the label `fleet.azure.com/location: westus`. +- The PickN placement policy selects 2 clusters based on the label `fleet.azure.com/location: westus`. Consequently, it chooses Member Cluster 1 and Member Cluster 2, as they are located in WestUS. - It targets resources in the `test-app` namespace. -## Migrating Applications to a Cluster in a Different Region -When the clusters in WestUS go down, update the ClusterResourcePlacement (CRP) to migrate the applications to another region. -For this tutorial, we will move them to WestEurope. +## Migrating Applications to a Cluster to Other Operational Clusters +When the clusters in WestUS go down, update the ClusterResourcePlacement (CRP) to migrate the applications to other clusters. +In this tutorial, we will move them to Member Cluster 4 and Member Cluster 5, which are located in WestEurope. -#### Update the CRP for Migration to WestEurope Cluster +#### Update the CRP for Migration to Clusters in WestEurope ```yaml apiVersion: placement.kubernetes-fleet.io/v1 kind: ClusterResourcePlacement @@ -274,11 +274,11 @@ kubectl apply -f crp.yaml ### Results After applying the updated `crp.yaml`, the Fleet will schedule the application on the available clusters in WestEurope. -You can check the status of the CRP to ensure that the application has been successfully migrated and is running in the new region: +You can check the status of the CRP to ensure that the application has been successfully migrated and is running on the newly selected clusters: ```bash kubectl get crp crp-migration -o yaml ``` -You should see a status indicating that the application is now running in the WestEurope clusters, similar to the following: +You should see a status indicating that the application is now running in the clusters located in WestEurope, similar to the following: #### CRP Status ```yaml ...