Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 【SOP 系列 39】通过 TiOperator 部署 TiDB
|
username: Billmay表妹
Thank you @清风明月 for your contribution
Deploy TiDB Operator
Download TiDB Cluster CRD Deployment File
wget https://raw.githubusercontent.com/pingcap/tidb-operator/master/manifests/crd.yaml
Create 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
Check CRD Status
[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
Install and Configure TiDB Operator
Method 1: Using YAML
Download TiDB Operator Docker Images
docker 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
Create TiDB Operator Deployment File
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.7
subjects:
- 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/instance: tidb-operator
app.kubernetes.io/component: scheduler
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: scheduler
template:
metadata:
labels:
app.kubernetes.io/name: tidb-operator
app.kubernetes.io/instance: tidb-operator
app.kubernetes.io/component: scheduler
spec:
serviceAccount: tidb-scheduler
containers:
- name: tidb-scheduler
image: pingcap/tidb-operator:v1.1.7
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: 250m
memory: 150Mi
requests:
cpu: 80m
memory: 50Mi
command:
- /usr/local/bin/tidb-scheduler
- -v=2
- -port=10262
- name: kube-scheduler
image: k8s.gcr.io/kube-scheduler:v1.14.0
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: 250m
memory: 150Mi
requests:
cpu: 80m
memory: 50Mi
command:
- kube-scheduler
- --port=10261
- --leader-elect=true
- --lock-object-name=tidb-scheduler
- --lock-object-namespace=tidb-admin
- --scheduler-name=tidb-scheduler
- --v=2
- --policy-configmap=tidb-scheduler-policy
- --policy-configmap-namespace=tidb-admin
Create TiDB Operator
## create tidb-admin namespace
[root@r21 soft]# kubectl create namespace tidb-admin
## create tidb-operator
[root@r21 soft]# kubectl apply -f tidb-operator-deploy.yaml -n tidb-admin
Check TiDB Operator Status
[root@k8s-master tidb-operator]# kubectl get pods -n tidb-admin
NAME READY STATUS RESTARTS AGE
tidb-controller-manager-6fb99fdb64-5zssz 1/1 Running 28 13d
tidb-scheduler-9f9c785c5-x42b4 2/2 Running 17 29d
Method 2: Using Helm
Add PingCAP Repository
helm repo add pingcap https://charts.pingcap.org/
Create Namespace
kubectl create namespace tidb-admin
Install TiDB Operator
helm install --namespace tidb-admin tidb-operator pingcap/tidb-operator --version v1.3.3 \
--set operatorImage=registry.cn-beijing.aliyuncs.com/tidb/tidb-operator:v1.3.3 \
--set tidbBackupManagerImage=registry.cn-beijing.aliyuncs.com/tidb/tidb-backup-manager:v1.3.3 \
--set