github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/kubeblocks-for-mongodb/cluster-management/switchover.md (about) 1 --- 2 title: Switch over a MongoDB cluster 3 description: How to switch over a MongoDB cluster 4 keywords: [mongodb, switch over a cluster, switchover] 5 sidebar_position: 6 6 sidebar_label: Switchover 7 --- 8 9 # Switch over a MongoDB cluster 10 11 You can initiate a switchover for a MongoDB ReplicaSet by executing the kbcli or kubectl command. Then KubeBlocks modifies the instance roles. 12 13 ## Before you start 14 15 * Make sure the cluster is running normally. 16 * Check whether the following role probe parameters exist to verify whether the role probe is enabled. 17 18 ```bash 19 kubectl get cd mongodb -o yaml 20 > 21 probes: 22 roleProbe: 23 failureThreshold: 3 24 periodSeconds: 2 25 timeoutSeconds: 1 26 ``` 27 28 ## Initiate the switchover 29 30 You can switch over a secondary of a MongoDB ReplicaSet to the primary role, and the former primary instance to a secondary. 31 32 <Tabs> 33 34 <TabItem value="kbcli" label="kbcli" default> 35 36 * Switchover with no primary instance specified 37 38 ```bash 39 kbcli cluster promote mycluster 40 ``` 41 42 * Switchover with a specified new primary instance 43 44 ```bash 45 kbcli cluster promote mycluster --instance='mycluster-mongodb-2' 46 ``` 47 48 * If there are multiple components, you can use `--component` to specify a component. 49 50 ```bash 51 kbcli cluster promote mycluster --instance='mycluster-mongodb-2' --component='mongodb' 52 ``` 53 54 </TabItem> 55 56 <TabItem value="kubectl" label="kubectl"> 57 58 The value of `instanceName` decides whether a new primary instance is specified for the switchover. 59 60 * Switchover with no specified primary instance 61 62 ```yaml 63 kubectl apply -f -<<EOF 64 apiVersion: apps.kubeblocks.io/v1alpha1 65 kind: OpsRequest 66 metadata: 67 name: mycluster-switchover-jhkgl 68 spec: 69 clusterRef: mycluster 70 type: Switchover 71 switchover: 72 - componentName: mongodb 73 instanceName: '*' 74 >> 75 ``` 76 77 * Switchover with a specified new primary instance 78 79 ```yaml 80 kubectl apply -f -<<EOF 81 apiVersion: apps.kubeblocks.io/v1alpha1 82 kind: OpsRequest 83 metadata: 84 name: mycluster-switchover-jhkgl 85 spec: 86 clusterRef: mycluster 87 type: Switchover 88 switchover: 89 - componentName: mongodb 90 instanceName: 'mycluster-mongodb-2' 91 >> 92 ``` 93 94 </TabItem> 95 96 </Tabs> 97 98 ## Verify the switchover 99 100 Check the instance status to verify whether the switchover is performed successfully. 101 102 ```bash 103 kbcli cluster list-instances 104 ``` 105 106 ## Handle an exception 107 108 If an error occurs, refer to [Handle an exaception](./../../handle-an-exception/handle-a-cluster-exception.md) to troubleshoot the operation.