栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

管理 TiDB 集群的 Command Cheat Sheet

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

管理 TiDB 集群的 Command Cheat Sheet

本文提供管理 TiDB 集群的 Command Cheat Sheet。

kubectl

查看资源
  • 查看 CRD:

     

    kubectl get crd

  • 查看 TidbCluster:

     

    kubectl -n ${namespace} get tc ${name}

  • 查看 TidbMonitor:

     

    kubectl -n ${namespace} get tidbmonitor ${name}

  • 查看 Backup:

     

    kubectl -n ${namespace} get bk ${name}

  • 查看 BackupSchedule:

     

    kubectl -n ${namespace} get bks ${name}

  • 查看 Restore:

     

    kubectl -n ${namespace} get restore ${name}

  • 查看 TidbClusterAutoScaler:

     

    kubectl -n ${namespace} get tidbclusterautoscaler ${name}

  • 查看 TidbInitializer:

     

    kubectl -n ${namespace} get tidbinitializer ${name}

  • 查看 Advanced StatefulSet:

     

    kubectl -n ${namespace} get asts ${name}

  • 查看 Pod:

     

    kubectl -n ${namespace} get pod ${name}

    查看 TiKV Pod:

     

    kubectl -n ${namespace} get pod -l app.kubernetes.io/component=tikv

    持续观察 Pod 状态变化:

     

    watch kubectl -n ${namespace} get pod

    查看 Pod 详细信息:

     

    kubectl -n ${namespace} describe pod ${name}

  • 查看 Pod 所在 Node:

     

    kubectl -n ${namespace} get pods -l "app.kubernetes.io/component=tidb,app.kubernetes.io/instance=${cluster_name}" -ojsonpath="{range .items[*]}{.spec.nodeName}{'n'}{end}"

  • 查看 Service:

     

    kubectl -n ${namespace} get service ${name}

  • 查看 ConfigMap:

     

    kubectl -n ${namespace} get cm ${name}

  • 查看 PV:

     

    kubectl -n ${namespace} get pv ${name}

    查看集群使用的 PV:

     

    kubectl get pv -l app.kubernetes.io/namespace=${namespace},app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/instance=${cluster_name}

  • 查看 PVC:

     

    kubectl -n ${namespace} get pvc ${name}

  • 查看 StorageClass:

     

    kubectl -n ${namespace} get sc

  • 查看 StatefulSet:

     

    kubectl -n ${namespace} get sts ${name}

    查看 StatefulSet 详细信息:

     

    kubectl -n ${namespace} describe sts ${name}

更新资源
  • 为 TiDBCluster 增加 Annotation:

     

    kubectl -n ${namespace} annotate tc ${cluster_name} ${key}=${value}

    为 TiDBCluster 增加强制升级 Annotation:

     

    kubectl -n ${namespace} annotate --overwrite tc ${cluster_name} tidb.pingcap.com/force-upgrade=true

    为 TiDBCluster 删除强制升级 Annotation:

     

    kubectl -n ${namespace} annotate tc ${cluster_name} tidb.pingcap.com/force-upgrade-

    为 Pod 开启 Debug 模式:

     

    kubectl -n ${namespace} annotate pod ${pod_name} runmode=debug

编辑资源
  • 编辑 TidbCluster:

     

    kubectl -n ${namespace} edit tc ${name}

Patch 资源
  • 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 PVC:

     

    kubectl -n ${namespace} patch pvc ${name} -p '{"spec": {"resources": {"requests": {"storage": "100Gi"}}}'

  • Patch StorageClass:

     

    kubectl patch storageclass ${name} -p '{"allowVolumeExpansion": true}'

创建资源
  • 通过 Yaml 文件创建集群:

     

    kubectl -n ${namespace} apply -f ${file}

  • 创建 Namespace:

     

    kubectl create ns ${namespace}

  • 创建 Secret:

    创建证书的 Secret:

     

    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}

    创建用户名、密码的 Secret:

     

    kubectl -n ${namespace} create secret generic ${secret_name} --from-literal=user=${user} --from-literal=password=${password}

与 Running Pod 交互
  • 查看 PD 配置文件:

     

    kubectl -n ${namespace} -it exec ${pod_name} -- cat /etc/pd/pd.toml

  • 查看 TiDB 配置文件:

     

    kubectl -n ${namespace} -it exec ${pod_name} -- cat /etc/tidb/tidb.toml

  • 查看 TiKV 配置文件:

     

    kubectl -n ${namespace} -it exec ${pod_name} -- cat /etc/tikv/tikv.toml

  • 查看 Pod Log:

     

    kubectl -n ${namespace} logs ${pod_name} -f

    查看上一次容器的 Log:

     

    kubectl -n ${namespace} logs ${pod_name} -p

    如果 Pod 内有多个容器,查看某一个容器的 Log:

     

    kubectl -n ${namespace} logs ${pod_name} -c ${container_name}

  • 暴露服务:

     

    kubectl -n ${namespace} port-forward svc/${service_name} ${local_port}:${port_in_pod}

    暴露 PD 服务:

     

    kubectl -n ${namespace} port-forward svc/${cluster_name}-pd 2379:2379

与 Node 交互
  • 把 Node 设置为不可调度:

     

    kubectl cordon ${node_name}

  • 取消 Node 不可调度:

     

    kubectl uncordon ${node_name}

删除资源
  • 删除 Pod:

     

    kubectl delete -n ${namespace} pod ${pod_name}

  • 删除 PVC:

     

    kubectl delete -n ${namespace} pvc ${pvc_name}

  • 删除 TidbCluster:

     

    kubectl delete -n ${namespace} tc ${tc_name}

  • 删除 TidbMonitor:

     

    kubectl delete -n ${namespace} tidbmonitor ${tidb_monitor_name}

  • 删除 TidbClusterAutoScaler:

     

    kubectl -n ${namespace} delete tidbclusterautoscaler ${name}

更多

其他更多 kubectl 的使用,请参考 Kubectl Cheat Sheet。

Helm

添加 Helm repository
 

helm repo add pingcap https://charts.pingcap.org/

更新 Helm repository
 

helm repo update

查看可用的 Helm Chart
  • 查看 Helm Hub 中的 Chart

     

    helm search hub ${chart_name}

    示例:

     

    helm search hub mysql

  • 查看其他 repository 中的 Chart

     

    helm search repo ${chart_name} -l --devel

    示例:

     

    helm search repo tidb-operator -l --devel

获取 Helm Chart 默认 values.yaml
 

helm inspect values ${chart_name} --version=${chart_version} > values.yaml

示例:

 

helm inspect values pingcap/tidb-operator --version=v1.3.6 > values-tidb-operator.yaml

使用 Helm Chart 部署
 

helm install ${name} ${chart_name} --namespace=${namespace} --version=${chart_version} -f ${values_file}

示例:

 

helm install tidb-operator pingcap/tidb-operator --namespace=tidb-admin --version=v1.3.6 -f values-tidb-operator.yaml

查看已经部署的 Helm Release
 

helm ls

升级 Helm Release
 

helm upgrade ${name} ${chart_name} --version=${chart_version} -f ${values_file}

示例:

 

helm upgrade tidb-operator pingcap/tidb-operator --version=v1.3.6 -f values-tidb-operator.yaml

删除 Helm Release
 

helm uninstall ${name} -n ${namespace}

示例:

 

helm uninstall tidb-operator -n tidb-admin

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1014838.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号