[root@shawnyan ~]# go version go version go1.21.9 linux/amd64 [root@shawnyan ~]# [root@shawnyan ~]# docker --version Docker version 26.1.2, build 211e74b [root@shawnyan ~]# [root@shawnyan ~]# kubectl version --client Client Version: v1.30.0 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
(only can deploy kb with docker, can not launch with podman.)
3. 创建 k8s 集群
本文仅做 PoC 演示,非标准生产环境部署步骤,因此这里使用 kind 创建 k8s 集群。
1 2
kind create cluster kubectl cluster-info
输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
[root@shawnyan ~]# kind create cluster Creating cluster "kind" ... ✓ Ensuring node image (kindest/node:v1.29.2) 🖼 ✓ Preparing nodes 📦 ✓ Writing configuration 📜 ✓ Starting control-plane 🕹️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ ✓ Installing CNI 🔌 ✓ Installing StorageClass 💾 Set kubectl context to "kind-kind" You can now use your cluster with:
kubectl cluster-info --context kind-kind
Thanks for using kind! 😊 [root@shawnyan ~]# kubectl cluster-info --context kind-kind Kubernetes control plane is running at https://127.0.0.1:34967 CoreDNS is running at https://127.0.0.1:34967/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@shawnyan ~]# kbcli playground init Create k3d cluster: kb-playground OK Merge kubeconfig to /root/.kube/config OK Switch current context to k3d-kb-playground OK Write kubeconfig to /root/.kbcli/playground/kubeconfig OK KubeBlocks will be installed to namespace "kb-system" Kubernetes version 1.23.8+k3s1 Kubernetes provider K3S kbcli version 0.8.2 Create CRDs OK Add and update repo kubeblocks OK Install KubeBlocks 0.8.2 OK Wait for addons to be enabled apecloud-mysql OK ... Create cluster mycluster (ClusterDefinition: apecloud-mysql) OK
KubeBlocks playground init SUCCESSFULLY!
Kubernetes cluster "kb-playground" has been created. Cluster "mycluster" has been created. Elapsed time: 5m50s ... [root@shawnyan ~]#
[root@shawnyan ~]# kbcli addon search tidb ADDON VERSION INDEX tidb 0.1.0-alpha.1 kubeblocks [root@shawnyan ~]# [root@shawnyan ~]# kbcli addon install tidb Default addon index "kubeblocks" has been added. addon tidb installed successfully [root@shawnyan ~]# [root@shawnyan ~]# kbcli addon list | egrep 'NAME|tidb' NAME VERSION PROVIDER STATUS AUTO-INSTALL tidb 0.1.0-alpha.1 community Enabled true [root@shawnyan ~]# [root@shawnyan ~]# kbcli addon enable tidb addon.extensions.kubeblocks.io/tidb enabled
2. 创建 TiDB 集群
使用 kbcli cluster 命令管理集群。
创建 TiDB 集群,并查看集群列表。
1 2 3 4 5 6 7
[root@shawnyan ~]# kbcli cluster create tidb-demo --cluster-definition tidb Info: --cluster-version is not specified, ClusterVersion tidb-v7.1.2 is applied by default Cluster tidb-demo created [root@shawnyan ~]# [root@shawnyan ~]# kbcli cluster list NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME tidb-demo default tidb tidb-v7.1.2 Delete Running May 10,2024 18:57 UTC+0800
这里可以看到,集群已创建成功,并运行正常。
查看集群定义和版本信息:
1 2 3 4 5 6 7
[root@shawnyan ~]# kbcli clusterdefinition list | egrep 'NAME|tidb' NAME MAIN-COMPONENT-NAME STATUS AGE tidb tidb Available 41h [root@shawnyan ~]# [root@shawnyan ~]# kbcli clusterversion list | egrep 'NAME|tidb' NAME CLUSTER-DEFINITION STATUS IS-DEFAULT CREATED-TIME tidb-v7.1.2 tidb Available false May 10,2024 18:48 UTC+0800
[root@shawnyan ~]# mysql -uroot -h127.0.0.1 -P4000 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 405 Server version: 5.7.25-TiDB-v7.1.2 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
Copyright (c) 2000, 2023, 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.
(root@127.0.0.1) [(none)]> select tidb_version()\G *************************** 1. row *************************** tidb_version(): Release Version: v7.1.2 Edition: Community Git Commit Hash: aa6ed99ae63191bc98e883fd4c369ae7482cccb7 Git Branch: heads/refs/tags/v7.1.2 UTC Build Time: 2023-10-21 07:46:04 GoVersion: go1.20.10 Race Enabled: false TiKV Min Version: 6.2.0-alpha Check Table Before Drop: false Store: tikv 1 row in set (0.01 sec)
(root@127.0.0.1) [(none)]> select now(); +---------------------+ | now() | +---------------------+ | 2024-05-12 01:16:40 | +---------------------+ 1 row in set (0.01 sec)