在K8S当中,进行TiDB的整体安装过程参考教程:tidb
1. 安装TIDB数据库
可以先创建两个Namespace专门存放TIDB相关的资源,tidb-admin存放TIDB的Operator相关的资源,tidb则存放TIDB数据库相关的资源。
kubectl create namespace tidb-admin
kubectl create namespace tidb
1.1 安装TIDB的CRD
安装CRD:
kubectl create -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.6.1/manifests/crd.yaml
如果需要修改的话,可以在本地修改资源清单之后再次执行
kubectl create -f crd.yaml
1.2 安装TIDB的Operator
可以通过如下的命令安装Operator:
# 添加tidb的仓库pingcap
helm repo add pingcap https://charts.pingcap.org/
# 创建tidb-admin的namespace用于部署tidb-operator
kubectl create namespace tidb-admin
# 安装tidb-operator
helm install --namespace tidb-admin tidb-operator pingcap/tidb-operator --version v1.6.1
接着,我们可以使用如下的命令,去查看tidb-operator服务是否已经正常启动。
kubectl get pods --namespace tidb-admin -l app.kubernetes.io/instance=tidb-operator
我们可以使用如下的命令输出yaml,再进行资源清单的修改(比如说修改镜像):
helm template --namespace tidb-admin tidb-operator pingcap/tidb-operator --version v1.6.1 > tidb-operator.yaml
下面是TIDB的Operator的完整文件,也可以使用如下的方式进行Operator的部署:
kubectl apply -f tidb-operator.yaml
1.3 部署TIDB集群
创建K8S集群:
kubectl create namespace tidb && \
kubectl -n tidb apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.6.1/examples/basic/tidb-cluster.yaml
kubectl -n tidb apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.6.1/examples/basic/tidb-dashboard.yaml
kubectl -n tidb apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.6.1/examples/basic/tidb-monitor.yaml
如果出现无法下载镜像等情况,那么可以下载yaml文件修改镜像源地址后执行安装。下面是完整的资源清单文件:
kubectl apply -f tidb-cluster.yaml -f tidb-dashboard.yaml -f tidb-monitor.yaml
1.4 基于MySQL客户端测试TIDB连接
可以使用如下的命令,基于MySQL客户端的方式,去连接目标TiDB数据库。
注意:这里需要指定的IP,是tidb对应的Service的ClusterIP,端口是TIDB的默认4000端口。
mysql -h 10.204.29.24 -P 4000 -u root
接着可以发现我们使用MySQL客户端,成功连接上目标TIDB服务器。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 488636514
Server version: 8.0.11-TiDB-v7.5.1 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
评论