基于Kubernetes部署TiDB v6.5.0

  1. 安装 TiDB Operator CRDs
    kubectl create -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.0/manifests/crd.yaml
    

无法访问时可点击crd.yaml下载,执行kubectl create -f crd.yaml

  1. 安装 TiDB Operator
  • 添加 PingCAP 仓库
    helm repo add pingcap https://charts.pingcap.org/
    
  • 为 TiDB Operator 创建一个命名空间
    kubectl create namespace tidb-admin
    
  • 安装 TiDB Operator
    helm install --namespace tidb-admin tidb-operator pingcap/tidb-operator --version v1.4.0 \
      --set operatorImage=registry.cn-beijing.aliyuncs.com/tidb/tidb-operator:v1.4.0 \
      --set tidbBackupManagerImage=registry.cn-beijing.aliyuncs.com/tidb/tidb-backup-manager:v1.4.0 \
      --set scheduler.kubeSchedulerImageName=registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler
    
  • 查看组件是否正常运行
    kubectl get pods --namespace tidb-admin -l app.kubernetes.io/instance=tidb-operator
    
    结果:
    NAME                                      READY   STATUS    RESTARTS   AGE
    tidb-controller-manager-bf5dbf8b7-6vbsj   1/1     Running   0          11s
    tidb-scheduler-57f7b749bc-766fv           2/2     Running   0          11s
    
  1. 部署TiDB集群
  • 创建命名空间

    kubectl create namespace tidb-cluster
    
  • 部署TiDB集群

    kubectl -n tidb-cluster apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.0/examples/basic/tidb-cluster.yaml
    

如果主机访问Docker Hub网速较慢,可改用UCloud:

kubectl -n tidb-cluster apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.0/examples/basic-cn/tidb-cluster.yaml

如果UCloud同样无法访问,可以通过以下方式:

vi tidb-cluster.yaml
# IT IS NOT SUITABLE FOR PRODUCTION USE.
# This YAML describes a basic TiDB cluster with minimum resource requirements,
# which should be able to run in any Kubernetes cluster with storage support.
apiVersion: pingcap.com/v1alpha1
kind: TidbCluster
metadata:
  name: tidb-cluster
spec:
  version: v6.5.0
  timezone: UTC
  pvReclaimPolicy: Retain
  enableDynamicConfiguration: true
  configUpdateStrategy: RollingUpdate
  discovery: {}
  helper:
    image: alpine:3.16.0
  pd:
    baseImage: uhub.service.ucloud.cn/pingcap/pd
    maxFailoverCount: 0
    replicas: 1
    # if storageClassName is not set, the default Storage Class of the Kubernetes cluster will be used
    # storageClassName: local-storage
    requests:
      storage: "1Gi"
    config: {}
  tikv:
    baseImage: uhub.service.ucloud.cn/pingcap/tikv
    maxFailoverCount: 0
    # If only 1 TiKV is deployed, the TiKV region leader 
    # cannot be transferred during upgrade, so we have
    # to configure a short timeout
    evictLeaderTimeout: 1m
    replicas: 3
    # if storageClassName is not set, the default Storage Class of the Kubernetes cluster will be used
    # storageClassName: local-storage
    requests:
      storage: "8Gi"
    config:
      storage:
        # In basic examples, we set this to avoid using too much storage.
        reserve-space: "0MB"
      rocksdb:
        # In basic examples, we set this to avoid the following error in some Kubernetes clusters:
        # "the maximum number of open file descriptors is too small, got 1024, expect greater or equal to 82920"
        max-open-files: 256
      raftdb:
        max-open-files: 256
  tidb:
    baseImage: uhub.service.ucloud.cn/pingcap/tidb
    maxFailoverCount: 0
    replicas: 1
    service:
      type: NodePort
      mysqlNodePort: 34000
      statusNodePort: 30080
    config: {}
kubectl apply -n tidb-cluster -f tidb-cluster.yaml
  1. 连接TiDB

有MySQL连接工具可直接使用工具连接
没有连接工具,可借助Docker打开MySQL容器连接

docker run --rm -it mysql /bin/sh

在容器中使用mysql命令登录,root用户默认无密码

mysql -h192.168.0.2 -P34000 -uroot
  1. 修改root密码
root@ksmaster-01:/home/master# docker run --rm -it mysql /bin/sh
sh-4.4# mysql -h10.24.1.30 -P34000 -uroot
mysql> set password for root@'%' = password('uJfBjRSH');
Query OK, 0 rows affected (0.48 sec)

也可以使用下面的方式修改密码:

root@ksmaster-01:/home/master# docker run --rm -it mysql /bin/sh
sh-4.4# mysqladmin -h192.168.0.2 -P34000 -uroot  password 'uJfBjRSH'

你可能感兴趣的:(kubernetes,tidb)