From 2aec9c94a19587c6539bc54c3cd1fc96925ecf66 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Fri, 20 Mar 2020 09:26:45 +0800 Subject: [PATCH] Add doc and examples for auto-scaler and intializer (#1772) * add doc and examples * fix by lint * revise the example * revise init * revise examples * Update tidb-cluster.yaml * revise by comment * revise examples * fix by lint * address the comment * Update examples/initialize/README.md Co-Authored-By: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com> * Update examples/auto-scale/README.md Co-Authored-By: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com> Co-authored-by: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com> --- examples/auto-scale/README.md | 50 ++++++++++++++ .../auto-scale/tidb-cluster-auto-scaler.yaml | 31 +++++++++ examples/auto-scale/tidb-cluster.yaml | 26 +++++++ examples/auto-scale/tidb-monitor.yaml | 20 ++++++ examples/initialize/README.md | 67 +++++++++++++++++++ examples/initialize/tidb-cluster.yaml | 26 +++++++ examples/initialize/tidb-initializer.yaml | 21 ++++++ 7 files changed, 241 insertions(+) create mode 100644 examples/auto-scale/README.md create mode 100644 examples/auto-scale/tidb-cluster-auto-scaler.yaml create mode 100644 examples/auto-scale/tidb-cluster.yaml create mode 100644 examples/auto-scale/tidb-monitor.yaml create mode 100644 examples/initialize/README.md create mode 100644 examples/initialize/tidb-cluster.yaml create mode 100644 examples/initialize/tidb-initializer.yaml diff --git a/examples/auto-scale/README.md b/examples/auto-scale/README.md new file mode 100644 index 0000000000..5bb7277d31 --- /dev/null +++ b/examples/auto-scale/README.md @@ -0,0 +1,50 @@ +# Deploying TidbCluster with Auto-scaling + +> **Note:** +> +> This setup is for test or demo purpose only and **IS NOT** applicable for critical environment. Refer to the [Documents](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/prerequisites/) for production setup. + + +The following steps will create a TiDB cluster with monitoring and auto-scaler, the monitoring data is not persisted by default. + +**Prerequisites**: +- Has TiDB operator `v1.1.0-beta.2` or higher version installed. [Doc](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/tidb-operator/) +- Has default `StorageClass` configured, and there are enough PVs (by default, 6 PVs are required) of that storageClass: + + This could be verified by the following command: + + ```bash + > kubectl get storageclass + ``` + + The output is similar to this: + + ```bash + NAME PROVISIONER AGE + standard (default) kubernetes.io/gce-pd 1d + gold kubernetes.io/gce-pd 1d + ``` + + Alternatively, you could specify the storageClass explicitly by modifying `tidb-cluster.yaml`. + + +## Enabling Auto-scaling + +> **Note:** +> +> The Auto-scaling feature is still in alpha, you should enable this feature in TiDB Operator by setting values.yaml: + ```yaml +features: + AutoScaling=true +``` + +Auto-scale the cluster based on CPU load +```bash +> kubectl -n apply -f ./ +``` + +## Destroy + +```bash +> kubectl -n delete -f ./ +``` diff --git a/examples/auto-scale/tidb-cluster-auto-scaler.yaml b/examples/auto-scale/tidb-cluster-auto-scaler.yaml new file mode 100644 index 0000000000..7727b8e0f2 --- /dev/null +++ b/examples/auto-scale/tidb-cluster-auto-scaler.yaml @@ -0,0 +1,31 @@ +apiVersion: pingcap.com/v1alpha1 +kind: TidbClusterAutoScaler +metadata: + name: auto-scaling-demo +spec: + cluster: + name: auto-scaling-demo + monitor: + name: auto-scaling-demo + tikv: + minReplicas: 3 + maxReplicas: 4 + metricsTimeDuration: "1m" + metrics: + - type: "Resource" + resource: + name: "cpu" + target: + type: "Utilization" + averageUtilization: 80 + tidb: + minReplicas: 2 + maxReplicas: 3 + metricsTimeDuration: "1m" + metrics: + - type: "Resource" + resource: + name: "cpu" + target: + type: "Utilization" + averageUtilization: 80 diff --git a/examples/auto-scale/tidb-cluster.yaml b/examples/auto-scale/tidb-cluster.yaml new file mode 100644 index 0000000000..f46ba9a659 --- /dev/null +++ b/examples/auto-scale/tidb-cluster.yaml @@ -0,0 +1,26 @@ +apiVersion: pingcap.com/v1alpha1 +kind: TidbCluster +metadata: + name: auto-scaling-demo +spec: + version: v3.0.8 + timezone: UTC + pvReclaimPolicy: Delete + pd: + baseImage: pingcap/pd + replicas: 3 + requests: + storage: "1Gi" + config: {} + tikv: + baseImage: pingcap/tikv + replicas: 3 + requests: + storage: "1Gi" + config: {} + tidb: + baseImage: pingcap/tidb + replicas: 2 + service: + type: ClusterIP + config: {} diff --git a/examples/auto-scale/tidb-monitor.yaml b/examples/auto-scale/tidb-monitor.yaml new file mode 100644 index 0000000000..c1c99bc95d --- /dev/null +++ b/examples/auto-scale/tidb-monitor.yaml @@ -0,0 +1,20 @@ +apiVersion: pingcap.com/v1alpha1 +kind: TidbMonitor +metadata: + name: auto-scaling-demo +spec: + clusters: + - name: auto-scaling-demo + prometheus: + baseImage: prom/prometheus + version: v2.11.1 + grafana: + baseImage: grafana/grafana + version: 6.0.1 + initializer: + baseImage: pingcap/tidb-monitor-initializer + version: v3.0.5 + reloader: + baseImage: pingcap/tidb-monitor-reloader + version: v1.0.1 + imagePullPolicy: IfNotPresent diff --git a/examples/initialize/README.md b/examples/initialize/README.md new file mode 100644 index 0000000000..6e4df651ad --- /dev/null +++ b/examples/initialize/README.md @@ -0,0 +1,67 @@ +# Creating TidbCluster with Initialization + +> **Note:** +> +> This setup is for test or demo purpose only and **IS NOT** applicable for critical environment. Refer to the [Documents](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/prerequisites/) for production setup. + + +The following steps will create a TiDB cluster with Initialization. + +**Prerequisites**: +- Has TiDB operator `v1.1.0-beta.1` or higher version installed. [Doc](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/tidb-operator/) +- Has default `StorageClass` configured, and there are enough PVs (by default, 6 PVs are required) of that storageClass: + + This could by verified by the following command: + + ```bash + > kubectl get storageclass + ``` + + The output is similar to this: + + ```bash + NAME PROVISIONER AGE + standard (default) kubernetes.io/gce-pd 1d + gold kubernetes.io/gce-pd 1d + ``` + + Alternatively, you could specify the storageClass explicitly by modifying `tidb-cluster.yaml`. + + +## Initialize + + +> **Note:** +> +> The Initialization should be done once the TiDB Cluster was created + +The following commands is assumed to be executed in this directory. + +You can create the root user and set its password by creating secret and link it to the Initializer: + +```bash +> kubectl create secret generic tidb-secret --from-literal=root= --namespace= +``` + +You can also create other users and set their password: +```bash +> kubectl create secret generic tidb-secret --from-literal=root= --from-literal=developer= --namespace= +``` + +Initialize the cluster to create the users and create the database named `hello`: + +```bash +> kubectl -n apply -f ./ +``` + +Wait for Initialize job done: +```bash +$ kubectl get pod -n | grep initialize-demo-tidb-initializer +initialize-demo-tidb-initializer-whzn7 0/1 Completed 0 57s +``` + +## Destroy + +```bash +> kubectl -n delete -f ./ +``` diff --git a/examples/initialize/tidb-cluster.yaml b/examples/initialize/tidb-cluster.yaml new file mode 100644 index 0000000000..1ec543ea72 --- /dev/null +++ b/examples/initialize/tidb-cluster.yaml @@ -0,0 +1,26 @@ +apiVersion: pingcap.com/v1alpha1 +kind: TidbCluster +metadata: + name: initialize-demo +spec: + version: v3.0.8 + timezone: UTC + pvReclaimPolicy: Delete + pd: + baseImage: pingcap/pd + replicas: 1 + requests: + storage: "1Gi" + config: {} + tikv: + baseImage: pingcap/tikv + replicas: 1 + requests: + storage: "1Gi" + config: {} + tidb: + baseImage: pingcap/tidb + replicas: 1 + service: + type: ClusterIP + config: {} diff --git a/examples/initialize/tidb-initializer.yaml b/examples/initialize/tidb-initializer.yaml new file mode 100644 index 0000000000..9067aff97b --- /dev/null +++ b/examples/initialize/tidb-initializer.yaml @@ -0,0 +1,21 @@ +apiVersion: pingcap.com/v1alpha1 +kind: TidbInitializer +metadata: + name: initialize-demo +spec: + image: tnir/mysqlclient + imagePullPolicy: IfNotPresent + cluster: + name: initialize-demo + initSql: "create database hello;" + # initSqlConfigMap: tidb-initsql + passwordSecret: "tidb-secret" + # permitHost: 172.6.5.8 + # resources: + # limits: + # cpu: 1000m + # memory: 500Mi + # requests: + # cpu: 100m + # memory: 50Mi + # timezone: "Asia/Shanghai"