Failover an application
In the event of a disaster, when one of your Kubernetes clusters becomes inaccessible, you have the option to failover the applications running on it to an operational Kubernetes cluster.
The following considerations are used in the examples on this page. Update them to the appropriate values for your environment:
- Source Cluster is the Kubernetes cluster which is down and where your applications were originally running.
- Destination Cluster is the Kubernetes cluster where the applications will be failed over to.
- The Zookeeper application is being failed over to the destination cluster.
Follow the instructions on this page to perform a failover of your applications to the destination cluster. These instructions apply to both scenarios, whether it is a controlled failover or a disaster recovery.
Prerequisites
-
You must ensure that Stork version 24.2.0 or newer is installed on both the source and destination clusters.
noteIf you are using a Stork version prior to 24.2.0, then you can follow this procedure to perform a failover.
-
For operators deployed from the OpenShift OperatorHub:
- Ensure that the operator is deployed on both the source and the destination clusters in the application namespace.
- Ensure that the migration schedule is created with the
--exclude-resource-types
flag to exclude operator-related resources, as shown in the following example:storkctl create migrationschedule -c cluster-pair -n zookeeper migration-schedule --exclude-resource-types ClusterServiceVersion,operatorconditions,OperatorGroup,InstallPlan,Subscription --exclude-selectors olm.managed=true
- Ensure that the operator and applications are in scaled down state on the source cluster. Stork will leverage
spec.replicas
from most of the standard Kubernetes controllers such as Deployments, StatefulSets, and so on. However, for applications managed by an Operator, anApplicationRegistration
CR needs to be created which provides Stork with the necessary information required to perform a scale down of the application. For more information, see the Application Registration document.
Perform failover
- Disaster recovery
- Controlled failover
In the event of a disaster, you can migrate an application or workload from the source cluster to destination cluster by running the storkctl perform failover
command.
You can include or exclude a subset of namespaces for migration by using one of the following flags:
--include-namespaces
- Use this flag to include a subset of namespaces for the migration.--exclude-namespaces
- Use this flag to exclude a subset of namespaces for the migration.
The --include-namespaces
and --exclude-namespaces
flags are mutually exclusive.
Are your clusters paired in a unidirectional manner? (Click to expand for more details)
--skip-source-operations
flag to skip the source cluster operations.To start the failover operation, run the following command in the destination cluster:
storkctl perform failover -m <migration-schedule> -n <migration-schedule-namespace>
If the last migration status is in the PartialSuccess
state, you'll be prompted to proceed with the failover operation. To bypass this prompt, use the --force
flag.
Example:
storkctl perform failover -m migration-schedule -n zookeeper
Started failover for MigrationSchedule zookeeper/migration-schedule
To check failover status use the command : `storkctl get failover failover-migration-schedule-2024-05-20-140139 -n zookeeper`
If your source cluster is accessible and you want to migrate an application or workload from the source cluster to destination cluster, you can perform a controlled failover by running the storkctl perform failover
command.
By default, Portworx scales down the resources and suspends the migration schedule in the source cluster, ensuring data consistency.
The cluster domain on the source cluster is deactivated, and Portworx volumes are stopped, resulting in the termination of the running applications on the source cluster.
You can customize this behavior using one of the following options. Use only one of these flags. If both are provided, Portworx prioritizes --skip-source-operations
and skips all source cluster operations.
-
If you want the applications to start on the destination cluster and don’t require data consistency between the source and destination clusters, use the
--skip-source-operations
flag. This skips all source cluster operations, including scaling down applications and deactivating the source cluster domain. -
If you want to scale down the applications in the source cluster but keep the source cluster domain active, use the
--skip-source-cluster-domain-deactivation
flag.
You can also include or exclude a subset of namespaces for migration by using one of the following flags:
--include-namespaces