Perform a Canary Upgrade on TiDB Operator
This document describes how to perform a canary upgrade on TiDB Operator. Using canary upgrades, you can prevent normal TiDB Operator upgrade from causing an unexpected impact on all the TiDB clusters in Kubernetes. After you confirm the impact of TiDB Operator upgrade or that the upgraded TiDB Operator works stably, you can normally upgrade TiDB Operator.
When you use TiDB Operator, tidb-scheduler is not mandatory. Refer to tidb-scheduler and default-scheduler to confirm whether you need to deploy tidb-scheduler.
note
- You can perform a canary upgrade only on
tidb-controller-managerandtidb-scheduler. AdvancedStatefulSet controller andtidb-admission-webhookdo not support the canary upgrade. - Canary upgrade is supported since v1.1.10. The version of your current TiDB Operator should be >= v1.1.10.
Related parameters​
To support canary upgrade, some parameters are added to the values.yaml file in the tidb-operator chart. See Related parameters for details.
Canary upgrade process​
Configure selector for the current TiDB Operator:
Refer to Upgrade TiDB Operator. Add the following configuration in the
values.yamlfile, and upgrade TiDB Operator:controllerManager:
selector:
- version!=canaryIf you have already performed the step above, skip to Step 2.
Deploy the canary TiDB Operator:
Refer to Deploy TiDB Operator. Add the following configuration in the
values.yamlfile, and deploy the canary TiDB Operator in a different namespace (such astidb-admin-canary) with a different Helm Release Name (such ashelm install tidb-operator-canary ...):controllerManager:
selector:
- version=canary
appendReleaseSuffix: true
#scheduler:
# If you do not need tidb-scheduler, set this value to false.
# create: false
advancedStatefulset:
create: false
admissionWebhook:
create: falseNote:
- It is recommended to deploy the new TiDB Operator in a separate namespace.
- Set
appendReleaseSuffixtotrue. - If you do not need to perform a canary upgrade on
tidb-scheduler, configurescheduler.create: false. - If you configure
scheduler.create: true, a scheduler named{{ .scheduler.schedulerName }}-{{.Release.Name}}will be created. To use this scheduler, configurespec.schedulerNamein theTidbClusterCR to the name of this scheduler. - You need to set
advancedStatefulset.create: falseandadmissionWebhook.create: false, because AdvancedStatefulSet controller andtidb-admission-webhookdo not support the canary upgrade.
To test the canary upgrade of
tidb-controller-manager, set labels for a TiDB cluster by running the following command:kubectl -n ${namespace} label tc ${cluster_name} version=canaryCheck the logs of the two deployed
tidb-controller-managers, and you can see this TiDB cluster is now managed by the canary TiDB Operator:View the log of
tidb-controller-managerof the current TiDB Operator:kubectl -n tidb-admin logs tidb-controller-manager-55b887bdc9-lzdwvI0305 07:52:04.558973 1 tidb_cluster_controller.go:148] TidbCluster has been deleted tidb-cluster-1/basic1View the log of
tidb-controller-managerof the canary TiDB Operator:kubectl -n tidb-admin-canary logs tidb-controller-manager-canary-6dcb9bdd95-qf4qrI0113 03:38:43.859387 1 tidbcluster_control.go:69] TidbCluster: [tidb-cluster-1/basic1] updated successfully
To test the canary upgrade of
tidb-scheduler, modifyspec.schedulerNameof some TiDB cluster totidb-scheduler-canaryby running the following command:kubectl -n ${namespace} edit tc ${cluster_name}After the modification, all components in the cluster will be rolling updated.
Check the logs of
tidb-schedulerof the canary TiDB Operator, and you can see this TiDB cluster is now using the canarytidb-scheduler:kubectl -n tidb-admin-canary logs tidb-scheduler-canary-7f7b6c7c6-j5p2j -c tidb-schedulerAfter the tests, you can revert the changes in Step 3 and Step 4 so that the TiDB cluster is again managed by the current TiDB Operator.
kubectl -n ${namespace} label tc ${cluster_name} version-kubectl -n ${namespace} edit tc ${cluster_name}Delete the canary TiDB Operator:
helm -n tidb-admin-canary uninstall ${release_name}Refer to Upgrade TiDB Operator and upgrade the current TiDB Operator normally.