Suspend TiDB cluster
This document introduces how to suspend the TiDB cluster or suspend the TiDB cluster components on Kubernetes by configuring the TidbCluster
object. After suspending the cluster, you can stop the Pods of all components or one specific component and retain the TidbCluster
object and other resources (such as Service and PVC).
In some test scenarios, if you need to save resources, you can suspend the TiDB cluster when you are not using it.
Configure TiDB cluster suspending
If you need to suspend the TiDB cluster, take the following steps:
In the
TidbCluster
object, configurespec.suspendAction
field to suspend the entire TiDB cluster:apiVersion: pingcap.com/v1alpha1 kind: TidbCluster metadata: name: ${cluster_name} namespace: ${namespace} spec: suspendAction: suspendStatefulSet: true # ...TiDB Operator also supports suspending one or more components in TiDB clusters. Taking TiKV as an example, you can suspend TiKV in the TiDB cluster by configuring
spec.tikv.suspendAction
field in theTidbCluster
object:apiVersion: pingcap.com/v1alpha1 kind: TidbCluster metadata: name: ${cluster_name} namespace: ${namespace} spec: tikv: suspendAction: suspendStatefulSet: true # ...After suspending the TiDB cluster, you can run the following command to observe that the Pods of the suspended component are gradually deleted.
kubectl -n ${namespace} get podsPods of each suspended component will be deleted in the following order:
- TiDB
- TiFlash
- TiCDC
- TiKV
- Pump
- TiProxy
- PD
Restore TiDB cluster
After a TiDB cluster or its component is suspended, if you need to restore the TiDB cluster, take the following steps:
In the
TidbCluster
object, configure thespec.suspendAction
field to restore the entire suspended TiDB cluster:apiVersion: pingcap.com/v1alpha1 kind: TidbCluster metadata: name: ${cluster_name} namespace: ${namespace} spec: suspendAction: suspendStatefulSet: false # ...TiDB Operator also supports restoring one or more components in the TiDB cluster. Taking TiKV as an example, you can restore TiKV in the TiDB cluster by configuring
spec.tikv.suspendAction
field in theTidbCluster
object.apiVersion: pingcap.com/v1alpha1 kind: TidbCluster metadata: name: ${cluster_name} namespace: ${namespace} spec: tikv: suspendAction: suspendStatefulSet: false # ...After restoring the TiDB cluster, you can run the following command to observe that the Pods of the suspended component are gradually created.
kubectl -n ${namespace} get pods