Command Cheat Sheet for TiDB Cluster Management
View CRD:
View TidbCluster:
kubectl -n ${namespace} get tc ${name}
View TidbMonitor:
kubectl -n ${namespace} get tidbmonitor ${name}
View Backup:
kubectl -n ${namespace} get bk ${name}
View BackupSchedule:
kubectl -n ${namespace} get bks ${name}
View Restore:
kubectl -n ${namespace} get restore ${name}
View TidbClusterAutoScaler:
kubectl -n ${namespace} get tidbclusterautoscaler ${name}
View TidbInitializer:
kubectl -n ${namespace} get tidbinitializer ${name}
View Advanced StatefulSet:
kubectl -n ${namespace} get asts ${name}
View a Pod:
kubectl -n ${namespace} get pod ${name}
View a TiKV Pod:
View the continuous status change of a Pod:
watch kubectl -n ${namespace} get pod
View the detailed information of a Pod:
kubectl -n ${namespace} describe pod ${name}
View the node on which Pods are located:
kubectl -n ${namespace} get pods -l "app.kubernetes.io/component=tidb,app.kubernetes.io/instance=${cluster_name}" -ojsonpath="{range .items[*]}{.spec.nodeName}{'\n'}{end}"
View Service:
kubectl -n ${namespace} get service ${name}
View ConfigMap:
kubectl -n ${namespace} get cm ${name}
View a PersistentVolume (PV):
kubectl -n ${namespace} get pv ${name}
View the PV used by the cluster:
kubectl get pv -l app.kubernetes.io/namespace=${namespace},app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/instance=${cluster_name}
View a PersistentVolumeClaim (PVC):
kubectl -n ${namespace} get pvc ${name}
-
kubectl -n ${namespace} get sc
View StatefulSet:
kubectl -n ${namespace} get sts ${name}
View the detailed information of StatefulSet:
Update resources
Add an annotation for TiDBCluster:
Add a force-upgrade annotation for TiDBCluster:
kubectl -n ${namespace} annotate --overwrite tc ${cluster_name} tidb.pingcap.com/force-upgrade=true
Delete a force-upgrade annotation for TiDBCluster:
kubectl -n ${namespace} annotate tc ${cluster_name} tidb.pingcap.com/force-upgrade-
Enable the debug mode for Pods:
kubectl -n ${namespace} annotate pod ${pod_name} runmode=debug
Edit resources
Edit TidbCluster:
kubectl -n ${namespace} edit tc ${name}
Patch Resources
Patch TidbCluster:
kubectl -n ${namespace} patch tc ${name} --type merge -p '${json_path}'
Patch PV ReclaimPolicy:
kubectl patch pv ${name} -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'
Patch a PVC:
kubectl -n ${namespace} patch pvc ${name} -p '{"spec": {"resources": {"requests": {"storage": "100Gi"}}}'
Patch StorageClass:
kubectl patch storageclass ${name} -p '{"allowVolumeExpansion": true}'
Create resources
Create a cluster using the YAML file:
kubectl -n ${namespace} apply -f ${file}
Create Namespace:
kubectl create ns ${namespace}
Create Secret:
Create Secret of the certificate:
kubectl -n ${namespace} create secret generic ${secret_name} --from-file=tls.crt=${cert_path} --from-file=tls.key=${key_path} --from-file=ca.crt=${ca_path}
Create Secret of the user id and password:
kubectl -n ${namespace} create secret generic ${secret_name} --from-literal=user=${user} --from-literal=password=${password}
Interact with running Pods
View the TiDB configuration file:
kubectl -n ${namespace} -it exec ${pod_name} -- cat /etc/tidb/tidb.toml
View the TiKV configuration file:
kubectl -n ${namespace} -it exec ${pod_name} -- cat /etc/tikv/tikv.toml
-
kubectl -n ${namespace} logs ${pod_name} -f
View logs of the previous container:
kubectl -n ${namespace} logs ${pod_name} -p
If there are multiple containers in a Pod, view logs of one container:
kubectl -n ${namespace} logs ${pod_name} -c ${container_name}
Expose services:
kubectl -n ${namespace} port-forward svc/${service_name} ${local_port}:${port_in_pod}
Expose PD services:
Mark the node as non-schedulable:
kubectl cordon ${node_name}
Mark the node as schedulable:
Delete resources
Delete a Pod:
kubectl delete -n ${namespace} pod ${pod_name}
Delete a PVC:
kubectl delete -n ${namespace} pvc ${pvc_name}
Delete TidbCluster:
kubectl delete -n ${namespace} tc ${tc_name}
Delete TidbMonitor:
kubectl delete -n ${namespace} tidbmonitor ${tidb_monitor_name}
Delete TidbClusterAutoScaler:
kubectl -n ${namespace} delete tidbclusterautoscaler ${name}
More
See for more kubectl usage.
Helm
Add Helm repository
helm repo add pingcap https://charts.pingcap.org/
Update Helm repository
helm repo update
View available Helm chart
View charts in Helm Hub:
helm search hub ${chart_name}
For example:
helm search hub mysql
View charts in other repositories:
helm search repo ${chart_name} -l --devel
For example:
helm search repo tidb-operator -l --devel
helm inspect values ${chart_name} --version=${chart_version} > values.yaml
For example:
helm inspect values pingcap/tidb-operator --version=v1.3.2 > values-tidb-operator.yaml
Deploy using Helm chart
helm install ${name} ${chart_name} --namespace=${namespace} --version=${chart_version} -f ${values_file}
For example:
helm install tidb-operator pingcap/tidb-operator --namespace=tidb-admin --version=v1.3.2 -f values-tidb-operator.yaml
View the deployed Helm release
helm ls
Update Helm release
helm upgrade ${name} ${chart_name} --version=${chart_version} -f ${values_file}
For example:
Delete Helm release
helm uninstall tidb-operator -n tidb-admin
More
See for more Helm usage.