Getting Started TiDB on GKE

See another post also to set up a TiDB on minikube.

To get the basic concept and architecture of TiDB, there are many articles and videos on the Internet, like following:

Set up a TiDB cluster by Kubernetes Operator

Follow the official document for GKE and the official document for kubernetes operator for this document.

ext4 file system configuration

It’s recommended to configure following options for better I/O performance for ext4 file system.

  • nodelalloc: Disable delayed allocation. See this option for why it’s enabled in the first place.
  • noatime: Disable to store access time on files. See this article for the benefit for this performance improvement.

The options of ext4 file system can be seen in this man document, though there is no noatime option.

Install TiDB CRD and its operator

First, create the namespace at first.

kubectl create namespace tidb-cluster

Then following this document, installing kubernetes operator.

kubectl create -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.0/manifests/crd.yaml
helm repo add pingcap https://charts.pingcap.org/
kubectl create namespace tidb-admin
helm install --namespace tidb-admin tidb-operator pingcap/tidb-operator --version v1.4.0

Confirm an installation on the operator

kubectl get pods --namespace tidb-admin -l app.kubernetes.io/instance=tidb-operator

Create a cluster

Create followings

  • the example of a cluster.
  • tidb dashboard (for some reasons, it doesn’t work)
  • tidb monitoring like prometheus and Grafana
kubectl -n tidb-cluster apply -f
https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.0/examples/basic/tidb-cluster
kubectl -n tidb-cluster apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.0/examples/basic/tidb-dashboard.yaml
kubectl -n tidb-cluster apply -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.0/examples/basic/tidb-monitor.yaml

Confirm the setup

watch kubectl get po -n tidb-cluster

Connect to TiDB

kubectl get svc -n tidb-cluster
kubectl port-forward -n tidb-cluster svc/basic-tidb 14000:4000 > pf14000.out &
mysql --comments -h 127.0.0.1 -P 14000 -u root mysql

Then create a table

use test;
create table hello_world (id int unsigned not null auto_increment primary key, v varchar(32));
select * from information_schema.tikv_region_status where db_name=database() and table_name='hello_world'\G

See the TiDB cluster information

select * from information_schema.cluster_info\G

Check Grafana

kubectl port-forward -n tidb-cluster svc/basic-grafana 3000 > pf3000.out &

Then go to [http://localhost:3000][] to see Grafana.

Check a TiDB Dashboard

I needed to update tidb-operator version to v1.4.2 because it was v1.3.5 and TiDBDashboard wasn’t created.

helm upgrade --namespace tidb-admin tidb-operator pingcap/tidb-operator --version v1.4.2 --set operatorImage='pingcap/tidb-operator:v1.4.2'

Once you make sure your TiDB Operator runs on v1.4.2, then run port-forward and access the TiDB dashboard

kubectl port-forward -n tidb-cluster svc/basic-tidb-dashboard-exposed 12333 > pf12333.out &

Access localhost:12333 on a browser.

If you want to use TopSQL and Continuous Profiling features, then deploy TidbNGMonitoring described in this document

Basic operations

Update the number of TiKV, TiDB, and PD nodes:

kubectl patch -n tidb-cluster tc basic --type merge --patch '{"spec":{"tikv":{"replicas":3}}}'
kubectl patch -n tidb-cluster tc basic --type merge --patch '{"spec":{"tidb":{"replicas":2}}}'
kubectl patch -n tidb-cluster tc basic --type merge --patch '{"spec":{"pd":{"replicas":2}}}'

Increase the amount of storage sizes of Network PV

Follow this document.

kubectl patch -n tidb-cluster tc basic --type merge --patch '{"spec":{"tikv":{"requests":{"storage":"100Gi"}}}}'

Note that Shrinking persistent volumes is not supported for Kubernetes Persistent Volumes.

Load an example data

At first, we’ll load the data from this example.

Before loading it, at first, check a storage engine on TiDB:

mysql> select * from information_schema.engines;
+--------+---------+------------------------------------------------------------+--------------+------+------------+
| ENGINE | SUPPORT | COMMENT                                                    | TRANSACTIONS | XA   | SAVEPOINTS |
+--------+---------+------------------------------------------------------------+--------------+------+------------+
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
+--------+---------+------------------------------------------------------------+--------------+------+------------+
1 row in set (0.04 sec)

Then expand storage sizes of TiKV nodes

kubectl patch -n tidb-cluster tc basic --type merge --patch '{"spec":{"tikv":{"requests":{"storage":"100Gi"}}}}'

Now it’s time to load the data by

tar xzvf test_db-1.0.7.tar.gz
cd test_db/
mysql --comments -h 127.0.0.1 -P 14000 -u root < employees.sql

Validate if the data is loaded correctly

mysql --comments -h 127.0.0.1 -P 14000 -u root employees < test_employees_md5.sql

In order to manage some components directly, install tiup and a few CLIs

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
tiup ctl:v6.5.0 pd

Control PD metadata

Following this document,

kubectl port-forward -n tidb-cluster svc/basic-pd 2379:2379 &>/tmp/portforward-pd.log &

Following commands are one of pd-ctl, listed in this document, like tiup ctl:v6.5.0 pd -u http://127.0.0.1:2379 cluster.

Manage a cluster

  • Confirm the cluster: cluster
  • Confirm the configuration: config show all

Manage PD members

  • Confirm the PD members: member
  • Confirm the leader: member leader show

Identify and analyze slow queries

See this document

  • Run queries on information_schema.SLOW LOG
  • Run the query ADMIN SHOW SLOW recent 10

2024

Back to Top ↑

2023

Follow Kubernetes the Hard way

4 minute read

This article was written by just following Kelsey Hightower’s Kubernetes Hardway document to understand Kubernetes internal architecture.

Gcp Billing Analyze

less than 1 minute read

There are a few documents to manage billing data in BigQuery Attribution of committed use discount fees and credits How to export to BigQuery Structur...

Prometheus Metrics Overview on Grafana

1 minute read

In this post, some variables defined in Grafana are used for Prometheus metrics, including $__rate_interval: This article describes the benefit of this va...

Use Google Secret Manager in a GKE cluster

3 minute read

There are an awesome article about the options to use the Google Secret Manager and their pros and cons. In this article, use Secrets Store CSI Driver by fol...

Working around MySQL lock metadata

2 minute read

There are multiple documents about innodb locks on MySQL 5.7: InnoDB locking Locks Set by Different SQL Statements in InnoDB Using InnoDB Transaction ...

Upgrade Windows 10 to Windows 11

3 minute read

I used to use Windows 11, but for some reasons, the OS stopped working and I needed to clean-install it from Windows 10 from windows recovery environment.

Back to Top ↑

2022

MySQL backup and restore

1 minute read

In this article, explain how to backup MySQL database using Percona Xtrabackup. There are two binaries, innobackupex and xtrabackup. innobackupex is a wrappe...

tmux

1 minute read

Basic configuration

Back to Top ↑

2021

MySQL Replication

1 minute read

This configuration is for the version 5.7 and it’s minimum configuration in the official document.

jq cheetsheet

less than 1 minute read

jq is used to parse JSON result, format and output on the cli.

Compare static site generator

less than 1 minute read

There are many web sites to compare static site generator, but they miss some explanations that require to me. For some people, these features are important ...

Back to Top ↑

2020

Getting Started with Kubernetes Deployment

less than 1 minute read

The deployment is many use cases and in this page, they’re not described. For the details for those use cases or the concept of deployment, see official page.

Overview about MySQL Lock

2 minute read

This document is written for MySQL 5.7, so these contents may be not correct for other versions.

MySQL Performance

2 minute read

This document is written for MySQL 5.7, so these contents may be not correct for other versions. In this page, performance_schema is mainly discussed.

Git hooks

less than 1 minute read

Configurations

gitHub pages

3 minute read

Getting Started See Official tutorial for detail steps.

Gitconfig

1 minute read

Configuration The detail for gitconfig is written in official page.

git cli

less than 1 minute read

Written in March 2020.

MySQL Tuner

less than 1 minute read

MySQL Tuner tool This is a tool to review a configuration for MySQL server.

kubectl cheetsheet

less than 1 minute read

Collect recent error logs If the logs are outputted by zap, error messages are aggregated by checking level = error. This log does not work very well if the ...

Introduction to GCP Cloud endpoints

less than 1 minute read

The Cloud endpoint is actually the NGINX proxy which offers the following features on GCP. Authentication and validation Logging and monitoring in GCP

HTTP/2 for Go

1 minute read

http package in golang supports HTTP/2 protocols. It’s automatically configured.

Back to Top ↑

2019

Terraform overview

1 minute read

Basic concepts There are some basic components for terraform.

Protocol Buffers for Go with Gadgets

less than 1 minute read

gogo/protobuf is the library to store some extensions from golang/protobuf in this repository. There are some useful packages that golang/protobuf does not p...

Introduction to GCP Cloud CDN

less than 1 minute read

Target upstream services Cloud CDN can have only GCP load balancer as the upstream services. And GCP load balancer can configure one of followings for backen...

Getting Started with Google closure library

less than 1 minute read

Some JavaScript library depends on Google Closure. If you need to understand the behavior of such a library, you have to know closure. The official document ...

Back to Top ↑