TiOperator 部署 TiDB 实操指南

网友投稿 579 2024-03-28



本文档介绍了如何通过 Kubernetes 集群,快速部署 TiDB Operator,并使用 TiDB Operator 部署 TiDB 集群。一步步操作能快速搭建一个基于容器的TiDB集群,并通过在搭建过程中出现的问题进行快速解答,力争通过该文档能进行一个快速的入门,由浅及深,保证100%搭建成功,作为一个入门级别的标准安装文档使用。

TiOperator 部署 TiDB 实操指南

部署TiDB Operator

下载TiDB Cluster CRD部署文件

wget https://raw.githubusercontent.com/pingcap/tidb-operator/master/manifests/crd.yaml

创建TiDB Cluster CRD

kubectl apply -f crd.yaml customresourcedefinition.apiextensions.k8s.io/tidbclusters.pingcap.com created customresourcedefinition.apiextensions.k8s.io/backups.pingcap.com created customresourcedefinition.apiextensions.k8s.io/restores.pingcap.com created customresourcedefinition.apiextensions.k8s.io/backupschedules.pingcap.com created customresourcedefinition.apiextensions.k8s.io/tidbmonitors.pingcap.com created customresourcedefinition.apiextensions.k8s.io/tidbinitializers.pingcap.com created customresourcedefinition.apiextensions.k8s.io/tidbclusterautoscalers.pingcap.com created

检查CRD状态

[root@k8s-master ~]# kubectl get crd |grep ping backups.pingcap.com 2022-03-28T07:46:10Z backupschedules.pingcap.com 2022-03-28T07:46:10Z dmclusters.pingcap.com 2022-03-28T07:46:11Z restores.pingcap.com 2022-03-28T07:46:11Z tidbclusterautoscalers.pingcap.com 2022-03-28T07:46:11Z tidbclusters.pingcap.com 2022-03-28T07:46:11Z tidbinitializers.pingcap.com 2022-03-28T07:46:12Z tidbmonitors.pingcap.com 2022-03-28T07:46:12Z tidbngmonitorings.pingcap.com 2022-03-28T07:46:12Z

安装配置TiDB Operator

方法一:通过yaml

下载TiDB Operator的docker iamgedocker pull pingcap/tidb-operator:v1.1.7 docker pull pingcap/tidb-backup-manager:v1.1.7 docker pull pingcap/advanced-statefulset:v0.3.3 mkdir -p /opt/soft/docker-image docker save -o tidb-backup-manager.tar pingcap/tidb-backup-manager docker save -o tidb-operator.tar pingcap/tidb-operator docker save -o advanced-statefulset.tar pingcap/advanced-statefulset创建tidb-operator部署文件cat tidb-operator-deploy.yaml ----------------------------------------------------------------------------------- # Source: tidb-operator/templates/scheduler-policy-configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: tidb-scheduler-policy labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: scheduler helm.sh/chart: tidb-operator-v1.1.7 data: policy.cfg: |- { "kind" : "Policy", "apiVersion" : "v1", "predicates": [ {"name": "NoVolumeZoneConflict"}, {"name": "MaxEBSVolumeCount"}, {"name": "MaxAzureDiskVolumeCount"}, {"name": "NoDiskConflict"}, {"name": "GeneralPredicates"}, {"name": "PodToleratesNodeTaints"}, {"name": "CheckVolumeBinding"}, {"name": "MaxGCEPDVolumeCount"}, {"name": "MatchInterPodAffinity"}, {"name": "CheckVolumeBinding"} ], "priorities": [ {"name": "SelectorSpreadPriority", "weight": 1}, {"name": "InterPodAffinityPriority", "weight": 1}, {"name": "LeastRequestedPriority", "weight": 1}, {"name": "BalancedResourceAllocation", "weight": 1}, {"name": "NodePreferAvoidPodsPriority", "weight": 1}, {"name": "NodeAffinityPriority", "weight": 1}, {"name": "TaintTolerationPriority", "weight": 1} ], "extenders": [ { "urlPrefix": "http://127.0.0.1:10262/scheduler", "filterVerb": "filter", "preemptVerb": "preempt", "weight": 1, "httpTimeout": 30000000000, "enableHttps": false } ] } --- # Source: tidb-operator/templates/controller-manager-rbac.yaml kind: ServiceAccount apiVersion: v1 metadata: name: tidb-controller-manager labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: controller-manager helm.sh/chart: tidb-operator-v1.1.7 --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: tidb-operator:tidb-controller-manager labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: controller-manager helm.sh/chart: tidb-operator-v1.1.7 rules: - apiGroups: [""] resources: - services -events verbs: ["*"] - apiGroups: [""] resources: ["endpoints","configmaps"] verbs: ["create", "get", "list", "watch", "update","delete"] - apiGroups: [""] resources: ["serviceaccounts"] verbs: ["create","get","update","delete"] - apiGroups: ["batch"] resources: ["jobs"] verbs: ["get", "list", "watch", "create", "update", "delete"] - apiGroups: [""] resources: ["secrets"] verbs: ["create", "update", "get", "list", "watch","delete"] - apiGroups: [""] resources: ["persistentvolumeclaims"] verbs: ["get", "list", "watch", "create", "update", "delete", "patch"] - apiGroups: [""] resources: ["pods"] verbs: ["get", "list", "watch","update", "delete"] - apiGroups: ["apps"] resources: ["statefulsets","deployments", "controllerrevisions"] verbs: ["*"] - apiGroups: ["extensions"] resources: ["ingresses"] verbs: ["*"] - apiGroups: ["apps.pingcap.com"] resources: ["statefulsets", "statefulsets/status"] verbs: ["*"] - apiGroups: ["pingcap.com"] resources: ["*"] verbs: ["*"] - nonResourceURLs: ["/metrics"] verbs: ["get"] - apiGroups: [""] resources: ["nodes"] verbs: ["get", "list", "watch"] - apiGroups: [""] resources: ["persistentvolumes"] verbs: ["get", "list", "watch", "patch","update"] - apiGroups: ["storage.k8s.io"] resources: ["storageclasses"] verbs: ["get", "list", "watch"] - apiGroups: ["rbac.authorization.k8s.io"] resources: [clusterroles,roles] verbs: ["escalate","create","get","update", "delete"] - apiGroups: ["rbac.authorization.k8s.io"] resources: ["rolebindings","clusterrolebindings"] verbs: ["create","get","update", "delete"] --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: tidb-operator:tidb-controller-manager labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: controller-manager helm.sh/chart: tidb-operator-v1.1.7 subjects: - kind: ServiceAccount name: tidb-controller-manager namespace: tidb-admin roleRef: kind: ClusterRole name: tidb-operator:tidb-controller-manager apiGroup: rbac.authorization.k8s.io --- # Source: tidb-operator/templates/scheduler-rbac.yaml kind: ServiceAccount apiVersion: v1 metadata: name: tidb-scheduler labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by:Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: scheduler helm.sh/chart: tidb-operator-v1.1.7 --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: tidb-operator:tidb-scheduler labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: scheduler helm.sh/chart: tidb-operator-v1.1.7 rules: # ConfigMap permission for --policy-configmap - apiGroups: [""] resources: ["configmaps"] verbs: ["get", "list", "watch"] - apiGroups: [""] resources: ["pods"] verbs: ["get", "list", "watch"] - apiGroups: [""] resources: ["nodes"] verbs: ["get", "list"] - apiGroups: ["pingcap.com"] resources: ["tidbclusters"] verbs: ["get"] - apiGroups: [""] resources: ["persistentvolumeclaims"] verbs: ["get", "list", "update"] # Extra permissions for endpoints other than kube-scheduler - apiGroups: [""] resources: ["endpoints"] verbs: ["delete", "get", "patch", "update"] - apiGroups: ["coordination.k8s.io"] resources: ["leases"] verbs: ["create"] - apiGroups: ["coordination.k8s.io"] resources: ["leases"]resourceNames: ["tidb-scheduler"] verbs: ["get", "update"] --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: tidb-operator:tidb-scheduler labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: scheduler helm.sh/chart: tidb-operator-v1.1.7 subjects: - kind: ServiceAccount name: tidb-scheduler namespace: tidb-admin roleRef:kind: ClusterRole name: tidb-operator:tidb-scheduler apiGroup: rbac.authorization.k8s.io --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: tidb-operator:kube-scheduler labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: scheduler helm.sh/chart: tidb-operator-v1.1.7 subjects: - kind: ServiceAccount name: tidb-scheduler namespace: tidb-admin roleRef: kind: ClusterRole name: system:kube-scheduler apiGroup: rbac.authorization.k8s.io --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: tidb-operator:volume-scheduler labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: scheduler helm.sh/chart: tidb-operator-v1.1.7subjects: - kind: ServiceAccount name: tidb-scheduler namespace: tidb-admin roleRef: kind: ClusterRole name: system:volume-scheduler apiGroup: rbac.authorization.k8s.io --- # Source: tidb-operator/templates/controller-manager-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: tidb-controller-manager labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by: Tiller app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: controller-manager helm.sh/chart: tidb-operator-v1.1.7 spec: replicas: 1 selector: matchLabels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: controller-manager template: metadata: labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/instance: tidb-operator app.kubernetes.io/component: controller-manager spec: serviceAccount: tidb-controller-manager containers: - name: tidb-operator image: pingcap/tidb-operator:v1.1.7 imagePullPolicy: IfNotPresent resources: requests: cpu: 80m memory: 50Mi command: - /usr/local/bin/tidb-controller-manager - -tidb-backup-manager-image=pingcap/tidb-backup-manager:v1.1.7 - -tidb-discovery-image=pingcap/tidb-operator:v1.1.7 - -cluster-scoped=true - -auto-failover=true - -pd-failover-period=5m - -tikv-failover-period=5m - -tiflash-failover-period=5m - -tidb-failover-period=5m - -v=2 env: - name: NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: TZ value: UTC --- # Source: tidb-operator/templates/scheduler-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: tidb-scheduler labels: app.kubernetes.io/name: tidb-operator app.kubernetes.io/managed-by:Tiller app.kubernetes.io/

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:TiKV节点重启后业务恢复速度比较 测试版本 v6.0 与 v5.1.2
下一篇:TiProxy 尝鲜体验
相关文章