Schedule migrations
Once your source and destination clusters are paired, you need to create a schedule to migrate one or more namespaces periodically. Because you have only one Portworx cluster stretched across your source and destination clusters, you will only migrate Kubernetes or OpenShift resources and not your volumes.
If you are using Stork version 24.2.0 or later, when you create a migration schedule in the source cluster, Stork automatically creates a corresponding migration schedule in the destination cluster. This migration schedule is used as a reference during the failover operation, and you must not manipulate this migration schedule on the destination cluster.
Create a schedule policy on your source cluster
You have two options for creating a schedule policy:
-
Use the
storkctl create schedulepolicycommand with the required flags. For more details and examples, refer to the Create schedule policy with storkctl section. -
Alternatively, to schedule a migration, you must define a schedule policy. You can select from two types of policies:
- SchedulePolicy: A cluster-scoped policy that applies to the entire cluster.
- NamespacedSchedulePolicy: A namespace-scoped policy that applies only to the specified namespace in the policy spec.
Follow the steps below to create a schedule policy on your source cluster:
-
Create a spec file using one of the following methods.
-
For
SchedulePolicy, create the following spec file:apiVersion: stork.libopenstorage.org/v1alpha1kind: SchedulePolicymetadata:name: <your-schedule-policy>policy:interval:intervalMinutes: 30For a list of parameters that you can use to create a schedule policy, see the Schedule Policy page.
-
For
NamespacedSchedulePolicy, create the following spec file:apiVersion: stork.libopenstorage.org/v1alpha1kind: NamespacedSchedulePolicymetadata:name: <your-schedule-policy>namespace: <migrationnamespace>policy:interval:intervalMinutes: 30For a list of parameters that you can use to create a namespaced policy, you can use the fields described on the Schedule Policy page, replacing
SchedulePolicywithNamespacedSchedulePolicy. -
You can also use the schedule policies that are installed by default. Run the
storkctl get schedulepolicycommand to get the list of these policies, then specify a policy name in the next section for creating a migration schedule. You can skip the next step if you are using the default policies, as they are already applied to your cluster.
-
-
Apply your policy on the source cluster:
- Kubernetes
- OpenShift
kubectl apply -f <your-schedule-policy>.yaml
oc apply -f <your-schedule-policy>.yaml
-
Verify if the policy has been created:
storkctl get schedulepolicy <your-schedule-policy>NAME INTERVAL-MINUTES DAILY WEEKLY MONTHLY<your-schedule-policy> 30 N/A N/A N/A
Create a migration schedule on your source cluster
Once a policy has been created, you can use it to schedule migrations.
For operators deployed from the OpenShift OperatorHub, create a migration schedule with the --exclude-resource-types flag to exclude operator-related resources, as shown in the following example:
storkctl create migrationschedule -c <cluster-pair> --namespaces <namespace> <migration-schedule> --exclude-resource-types ClusterServiceVersion,operatorconditions,OperatorGroup,InstallPlan,Subscription --exclude-selectors olm.managed=true
You have two options for creating a migration schedule:
-
Run the
storkctl create migrationschedulecommand-line tool along with the required flags. See Create migration schedule with storkctl topic for more information about the commands with examples.noteTo validate which resources will be included in a MigrationSchedule before creating it, use the
--previewor--preview-fileflags with thestorkctl create migrationschedulecommand. This helps ensure that all required resources—namespaced and non-namespaced—are identified in advance. For more information, see Preview resources before creating migration schedule.or
-
Perform the following steps on your source cluster:
-
Copy and paste the following spec into a file called
migrationschedule.yaml. Modify the following spec to use a different migration schedule name and/or namespace. Ensure that theclusterPairname is correct.noteIf you have created an admin ClusterPair, you can use it instead of creating a local ClusterPair. Use the
spec.template.spec.adminClusterPairfield instead ofspec.template.spec.clusterPair.apiVersion: stork.libopenstorage.org/v1alpha1kind: MigrationSchedulemetadata:name: migrationschedulenamespace: <migrationnamespace>spec:template:spec:clusterPair: <your-clusterpair-name>includeResources: truestartApplications: falseincludeVolumes: falsenamespaces:- <app-namespace1>- <app-namespace2>schedulePolicyName: <your-schedule-policy>suspend: falseautoSuspend: true
note- The option
startApplicationsmust be set to false in the spec to ensure that the application pods do not start on the remote cluster when the Kubernetes or OpenShift resources are being migrated. - The option
includeVolumesis set to false because the volumes are already present on the destination cluster as this is a single Portworx cluster. - With Stork 23.2 or newer, you can set the
autoSuspendflag totrue, as shown in the above spec. In case of a disaster, this will suspend the DR migration schedules automatically on your source cluster, and you will be able to migrate your application to an active Kubernetes or OpenShift cluster. If you are using an older version of Stork, refer to the Failover an application page for achieving failover for your application.
- Apply your
migrationschedule.yamlby entering the following command:
- Kubernetes
- OpenShift
kubectl apply -f migrationschedule.yamloc apply -f migrationschedule.yamlIf the policy name is missing or invalid there will be events logged against the schedule object. Success and failures of the migrations created by the schedule will also result in events being logged against the object. These events can be seen by running a
kubectl describeoroc describecommand on the object. -
Migrate specific VMs with a migration schedule
Starting with Stork 26.5.0, you can limit a migration schedule to specific KubeVirt virtual machines (VMs) instead of migrating every resource in a namespace. You select the VMs by name. Stork automatically identifies the resources that each VM depends on, such as its PVCs and DataVolumes, and migrates them together with the VM. You do not need to label each dependency, and the other VMs in the namespace are not affected.
Prerequisites
Before migrating specific VMs, ensure that the following requirements are met:
- Stork version: Stork 26.5.0 or later is installed on both the source and destination clusters.
- ClusterPair: A ClusterPair is configured between the source and destination clusters.
- KubeVirt VMs: The namespaces that you want to migrate contain KubeVirt VMs.
Migration modes
The enforcePrimaryKind field in the MigrationSchedule specification determines what Stork migrates:
| Mode | enforcePrimaryKind | What Stork migrates |
|---|---|---|
| Default | Not set | Stork migrates all resources in the namespace. This is the existing behavior. |
| VMs only | true | Stork migrates only the kinds that you list in primaryKinds, which are VMs, and their dependencies. To migrate specific VMs, list their names in includeNames. |
| Everything except VMs | false | Stork migrates all resources in the namespace except the registered primary kinds, which are VMs, and their dependencies. Do not set primaryKinds in this mode. |
Create a migration schedule for specific VMs
To create a migration schedule for specific VMs, use one of the following methods:
-
Run the
storkctl create migrationschedulecommand with the--enforce-primary-kindand--primary-kindflags. For the commands and examples, see Create a migration schedule for specific VMs.or
-
Add the
enforcePrimaryKindandprimaryKindsfields to thespec.template.specsection of themigrationschedule.yamlfile that you created in Create a migration schedule on your source cluster, as shown in the following example.apiVersion: stork.libopenstorage.org/v1alpha1kind: MigrationSchedulemetadata:name: vm-migration-schedulenamespace: <migrationnamespace>spec:schedulePolicyName: <your-schedule-policy>template:spec:clusterPair: <clusterpair-name>includeVolumes: falsestartApplications: falsenamespaces:- <app-namespace>enforcePrimaryKind: trueprimaryKinds:- kind: kubevirt.io/v1/VirtualMachineincludeNames: # Omit includeNames to select all VMs in the namespace- <vm-name1>- <vm-name2>
To see the resources that Stork migrates before you create the schedule, add the --preview flag to the storkctl create migrationschedule command.
Add or remove VMs on an existing schedule
To change which VMs a schedule covers without rewriting the schedule, use the storkctl update migrationschedule command. You can add VMs, remove VMs, or preview the change before you apply it.
The following example shows how to add a VM, remove a VM, and preview a change:
# Add the VM <vm-name> to the schedule <migration-schedule>
storkctl update migrationschedule <migration-schedule> \
--primary-kind=kubevirt.io/v1/VirtualMachine \
--add-names=<vm-name> \
-n <migrationnamespace>
# Remove the VM <vm-name> from the schedule <migration-schedule>
storkctl update migrationschedule <migration-schedule> \
--primary-kind=kubevirt.io/v1/VirtualMachine \
--remove-names=<vm-name> \
-n <migrationnamespace>
# Preview the resulting primaryKinds without applying the change
storkctl update migrationschedule <migration-schedule> \
--primary-kind=kubevirt.io/v1/VirtualMachine \
--add-names=<vm-name> \
--dry-run \
-n <migrationnamespace>
Replace <migration-schedule> with the name of the migration schedule, <vm-name> with the name of the VM, and <migrationnamespace> with the namespace of the migration schedule.
When an update succeeds, the command prints the following message:
MigrationSchedule <migrationnamespace>/<migration-schedule> updated
With the --dry-run flag, the command prints the resulting primaryKinds block without applying the change:
DRY RUN — resulting primaryKinds:
- includeNames:
- <vm-name>
kind: kubevirt.io/v1/VirtualMachine
For all options, see storkctl update migrationschedule.
Limitations
The following limitations apply when migrating specific VMs:
- VM selection: You can select VMs either by name with
includeNamesor by label with--selectorsand--exclude-selectors. Stork rejects a schedule that uses both. - Primary kinds: The only supported primary kind is
kubevirt.io/v1/VirtualMachine, and each kind can appear only once inprimaryKinds. Stork rejects any other primary kind. - Required settings:
enforcePrimaryKind: truerequires at least one entry inprimaryKinds. You can useprimaryKindsandincludeNamesonly whenenforcePrimaryKindistrue. Stork rejects these fields in the default mode or whenenforcePrimaryKindisfalse.
Check your migration status
-
Run the following command on your source cluster to check the status of your migration:
storkctl get migration -n <migrationnamespace>NAMESPACE NAME CLUSTERPAIR STAGE STATUS VOLUMES RESOURCES CREATED ELAPSED TOTAL BYTES TRANSFERREDbidirectional-clusterpair-ns <your-app>-migration-schedule-interval-interval-2023-08-28-015917 birectional-cluster-pair Final Successful 1/1 4/4 27 Aug 23 19:59 MDT Volumes (33s) Resources (1m2s) 4096-
The output above indicates a successful migration in the
Statuscolumn. It also provides a list of migration objects along with timestamps associated with your migration. -
You can also run the following command to check details about specific migrations:
- Kubernetes
- OpenShift
kubectl describe migration -n <migrationnamespace>oc describe migration -n <migrationnamespace>
-
-
Verify your application and associated resources have been migrated by running the following command on your destination cluster:
- Kubernetes
- OpenShift
kubectl get all -n zookeeperoc get all -n zookeeperNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/zk-service ClusterIP 10.xxx.xx.68 <none> xxxx/TCP 2m13sNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/zk 0/0 0 0 2m13sNAME DESIRED CURRENT READY AGEreplicaset.apps/zk-59d878d987 0 0 0 2m13s
This confirms that the respective namespace has been created and the applications (for example, Zookeeper) are installed. However, the application pods will not be running because they are running on the source cluster.
As part of every Migration, Stork will also migrate the Kubernetes or OpenShift resources associated with your applications. For a successful migration, these applications need to be in a scaled down state on the destination side so that subsequent migrations from the same schedule can run to completion. To achieve this Stork will leverage spec.replicas from most of the standard controllers such as Kubernetes Deployments, StatefulSets, and so on. However, for applications managed by an Operator an ApplicationRegistration CR needs to be created which provides Stork with the necessary information required to perform a scale down of the application. Refer to the ApplicationRegistrations page for more details.