官网介绍:在 Kubernetes 上快速上手 TiDB | PingCAP 文档中心
下面是具体细节:
一、安装
1.安装kind,一定要使用最新版本!!!
kind官网:kind – Quick Start
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.18.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
2.安装docker
更换国内源
安装依赖
sudo apt-get install apt-transport-https ca-certificates software-properties-common curl
安装阿里源gpg密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
安装Docker-ce(社区版)
sudo apt-get update
sudo apt-get install docker-ce
测试
sudo docker run hello-world
3.安装kubelet
snap install kubectl --classic# 查看kubectl版本
kubectl version --client
4.安装helm,官网:Helm | Installing Helm
wget https://get.helm.sh/helm-v3.11.3-linux-amd64.tar.gz
tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
二、操作,具体可参考tidb官网在 Kubernetes 上快速上手 TiDB | PingCAP 文档中心
#安装 TiDB Operator CRDs
kubectl create -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.4/manifests/crd.yaml
#安装 Helm 3 并使用 Helm 3 部署 TiDB Operator。
helm repo add pingcap https://charts.pingcap.org/
#为 TiDB Operator 创建一个命名空间,使用阿里云上的镜像。
helm install --namespace tidb-admin tidb-operator pingcap/tidb-operator --version v1.4.4 \--set operatorImage=registry.cn-beijing.aliyuncs.com/tidb/tidb-operator:v1.4.4 \--set tidbBackupManagerImage=registry.cn-beijing.aliyuncs.com/tidb/tidb-backup-manager:v1.4.4 \--set scheduler.kubeSchedulerImageName=registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler
#检查 TiDB Operator 组件是否正常运行起来:等待到都是running情况
kubectl get pods --namespace tidb-admin -l app.kubernetes.io/instance=tidb-operator
#部署 TiDB 集群
kubectl create namespace tidb-cluster && \kubectl -n tidb-cluster apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.4/examples/basic-cn/tidb-cluster.yaml
#部署独立的 TiDB Dashboard
kubectl -n tidb-cluster apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.4/examples/basic-cn/tidb-dashboard.yaml
#查看POD运行状态,等待都是running状态:
watch kubectl get po -n tidb-cluster
#获取 tidb-cluster 命名空间中的服务列表:
kubectl get svc -n tidb-cluster
#使用以下命令转发本地端口到集群
kubectl port-forward -n tidb-cluster svc/basic-tidb 14000:4000 > pf14000.out &
#连接tidb
mysql --comments -h 127.0.0.1 -P 14000 -u root
#暴露grafana端口
kubectl port-forward -n tidb-cluster svc/basic-grafana 3000 > pf3000.out &
#通过http://localhost:3000访问,admin admin
#暴露tidb dashboard
kubectl port-forward -n tidb-cluster svc/basic-tidb-dashboard-exposed 12333 > pf12333.out &
#通过 http://localhost:12333 访问,无密码
遇到坑:
1.basic-tidb-0 一直启动失败 :CrashLoopBackOff
去了tidb社区提问:basic-tidb-0 一直启动失败 :CrashLoopBackOff - TiDB 的问答社区
kubectl logs -n tidb-cluster -f basic-tidb-0 -c tidb 执行结果:
start tidb-server …
/tidb-server --store=tikv --advertise-address=basic-tidb-0.basic-tidb-peer.tidb-cluster.svc --host=0.0.0.0 --path=basic-pd:2379 --config=/etc/tidb/tidb.toml
–log-slow-query=/var/log/tidb/slowlog
[2023/04/24 01:34:12.357 +00:00] [INFO] [cpuprofile.go:113] [“parallel cpu profiler started”]
[2023/04/24 01:34:12.357 +00:00] [FATAL] [terror.go:300] [“unexpected error”] [error=“path "/docker/2e800829730d53f792c9ac0b32a64ff153094e9b7df0208d2bc9a14d31f4526b" is not a descendant of mount point root "/docker/2e800829730d53f792c9ac0b32a64ff153094e9b7df0208d2bc9a14d31f4526b/kubelet" and cannot be exposed from "/sys/fs/cgroup/rdma/kubelet"”] [stack=“github.com/pingcap/tidb/parser/terror.MustNil\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/parser/terror/terror.go:300\nmain.setGlobalVars\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/tidb-server/main.go:615\nmain.main\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/tidb-server/main.go:208\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250”] [stack=“github.com/pingcap/tidb/parser/terror.MustNil\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/parser/terror/terror.go:300\nmain.setGlobalVars\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/tidb-server/main.go:615\nmain.main\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/tidb-server/main.go:208\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250”]
解决办法:将kind从0.10升级到最新版本1.8版本,重新开始操作
kind delete cluster
升级kind
然后重新操作
2.Temporary failure in name resolution(域名解析暂时失败)
vm连接网络来回切换下,或者重启下虚拟机,暂时原因还没找到