Pause Sync of a TiDB Cluster in Kubernetes

    In TiDB Operator, controller regulates the state of the TiDB cluster in Kubernetes. The controller constantly compares the desired state recorded in the object with the actual state of the TiDB cluster. This process is referred to as sync generally. For more details, refer to TiDB Operator Architecture.

    Here are some cases where you might need to pause sync of a TiDB cluster in Kubernetes.

    • In some cases, you might need to continuously modify the cluster over a period of time, but do not want to restart the TiDB cluster many times. To avoid multiple rolling restarts, you can pause sync of the cluster. During the sync pausing, any change of the configuration does not take effect on the cluster. After you finish the modification, resume sync of the TiDB cluster. All changes can be applied in a single rolling restart.

    • Maintenance window

      In some situations, you can update or restart the TiDB cluster only during a maintenance window. When outside the maintenance window, you can pause sync of the TiDB cluster, so that any modification to the specs does not take effect. When inside the maintenance window, you can resume sync of the TiDB cluster to allow TiDB cluster to rolling update or restart.

    1. Execute the following command to edit the TiDB cluster configuration. ${cluster_name} represents the name of the TiDB cluster, and ${namespace} refers to the TiDB cluster namespace.

      1. The expected output is as follows. The sync of all components in the TiDB cluster is paused.

      To resume the sync of the TiDB cluster, configure spec.paused: false in the TidbCluster CR.

      1. Execute the following command to edit the TiDB cluster configuration. ${cluster_name} represents the name of the TiDB cluster, and ${namespace} refers to the TiDB cluster namespace.

        1. kubectl patch tc ${cluster_name} -n ${namespace} --type merge -p '{"spec":{"paused": false}}'
      2. To confirm the sync status of a TiDB cluster, execute the following command. represents the name of the tidb-controller-manager Pod, and ${namespace} represents the namespace of TiDB Operator.

        1. I1207 11:14:59.361353 1 tidb_cluster_controller.go:136] Finished syncing TidbCluster "default/basic" (368.816685ms)
        2. I1207 11:15:29.360446 1 tidb_cluster_controller.go:136] Finished syncing TidbCluster "default/basic" (377.51187ms)