K8S 使用Operator部署和管理TIDB

概述

tidb为分布式的newSQLdb,我们结合operator和k8s 完成tidb的部署和扩容

硬盘使用local卷,如何管理local卷请翻阅 我的另一篇文章

https://www.jianshu.com/p/bfa204cef8c0

k8s机器信息 版本1.13

node1 10.16.16.119  master节点

node2 10.16.16.120 master节点

node3 10.16.16.68  

node4 10.16.16.68

部署rcd资源

git clone https://github.com/pingcap/tidb-operator.git

cd /tidb-operator/

kubectl apply -f manifests/crd.yaml



安装TiDB Operator

查看可配置信息

helm inspect charts/tidb-operator

apiVersion: v1

description: tidb-operator Helm chart for Kubernetes

home: https://github.com/pingcap/tidb-operator

keywords:

- operator

- newsql

- htap

- database

- mysql

- raft

name: tidb-operator

sources:

- https://github.com/pingcap/tidb-operator

version: 0.1.0

---

# Default values for tidb-operator

# clusterScoped is whether tidb-operator should manage kubernetes cluster wide tidb clusters

# Also see rbac.create and controllerManager.serviceAccount

clusterScoped: true

# Also see clusterScoped and controllerManager.serviceAccount

rbac:

  create: true

# operatorImage is TiDB Operator image

operatorImage: pingcap/tidb-operator:latest

imagePullPolicy: IfNotPresent

defaultStorageClassName: local-storage

controllerManager:

  # With rbac.create=false, the user is responsible for creating this account

  # With rbac.create=true, this service account will be created

  # Also see rbac.create and clusterScoped

  serviceAccount: tidb-controller-manager

  logLevel: 2

  replicas: 1

  resources:

    limits:

      cpu: 250m

      memory: 150Mi

    requests:

      cpu: 80m

      memory: 50Mi

  # autoFailover is whether tidb-operator should auto failover when failure occurs

  autoFailover: false

  # pd failover period default(5m)

  pdFailoverPeriod: 5m

  # tidb failover period default(5m)

  tidbFailoverPeriod: 5m

scheduler:

  # With rbac.create=false, the user is responsible for creating this account

  # With rbac.create=true, this service account will be created

  # Also see rbac.create and clusterScoped

  serviceAccount: tidb-scheduler

  logLevel: 2

  replicas: 1

  schedulerName: tidb-scheduler

  resources:

    limits:

      cpu: 250m

      memory: 150Mi

    requests:

      cpu: 80m

      memory: 50Mi

  kubeSchedulerImageName: gcr.io/google-containers/hyperkube

  # This will default to matching your kubernetes version

  # kubeSchedulerImageTag:


指定自身参数,改变指定的image,因为gcr。io国内无法访问

有两种类型的存储hhd和ssd


vi ./w11_tidb-operator.config 

#这里使用的是local hhd

defaultStorageClassName: local-storage 

#defaultStorageClassName: ssd-local-storage 

scheduler:

  kubeSchedulerImageName: googlecontainer/hyperkube

  kubeSchedulerImageTag: v1.13.4


helm install charts/tidb-operator -f ./w11_tidb-operator.config  --name=tidb-operator --namespace=tidb-admin

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


如果全部ready即为创建成功

创建TIDB集群

查看配置参数

helm inspect charts/tidb-cluster

过多这里不在罗列,主要分为

pd的设置

tidb的设置

kv的设置

monitor的设置


编写定义参数

clusterName: w11tidb

pd:

  resources:

    limits:

      cpu: 4000m

      memory: 4Gi

    requests:

      cpu: 1000m

      memory: 1Gi

      storage: 1Gi

tikv:

  replicas: 3

  resources:

    limits:

      cpu: 16000m

      memory: 10Gi

      storage: 100Gi

    requests:

      cpu: 1000m

      memory: 2Gi

      storage: 5Gi

tidb:

  separateSlowLog: True

  replicas: 3

  resources:

    limits:

      cpu: 16000m

      memory: 6Gi

    requests:

      cpu: 1000m

      memory: 1Gi

monitor:

  persistent: true


helm install charts/tidb-cluster -f ./w11.config --name=tidb-cluster --namespace=tidb


kubectl get pods --namespace tidb -l app.kubernetes.io/instance=tidb-cluster -o wide

看出是否全部ok

查看端口

kubectl get svc --namespace tidb


监控为w11tidb-grafana,tidb为w11tidb-tidb

连接tidb


监控

http://10.16.16.119:30976

密码账号全部 admin admin



在线扩容TIDB


编写定义参数

将tikv 和 tidb从3个节点扩用值6个 resource提高

clusterName: w11tidb

pd:

  resources:

    limits:

      cpu: 4000m

      memory: 4Gi

    requests:

      cpu: 1000m

      memory: 1Gi

      storage: 1Gi

tikv:

  replicas: 6

  resources:

    limits:

      cpu: 16000m

      memory: 20Gi

      storage: 100Gi

    requests:

      cpu: 1000m

      memory: 2Gi

      storage: 5Gi

tidb:

  separateSlowLog: True

replicas: 6

  resources:

    limits:

      cpu: 16000m

      memory: 16Gi

    requests:

      cpu: 1000m

      memory: 1Gi

monitor:

  persistent: true


扩容

helm upgrade -f w11.config tidb-cluster ./charts/tidb-cluster/


观察节点情况

kubectl get pods --namespace tidb -l app.kubernetes.io/instance=tidb-cluster -o wide

两个节点扩用中,已有节点根据情况重启重新配置resource



slow收集的收集


开启单独记录slowlog

tidb:

  separateSlowLog: True

更新集群

helm upgrade -f w11.config tidb-cluster ./charts/tidb-cluster/

kubectl logs -n${namespace}${tidbPodName}-c slowlog

或者用stern

stern -n${namespace}tidb -c slowlog


备份

创建root账号

kubectl --namespace tidb create secret generic backup-secret --from-literal=user=root --from-literal=password=<password>


配置backup参数

helm inspect ./charts/tidb-backup/

vi ./w11_backup.config

clusterName: w11tidb

storage:

  className: local-storage

  size: 10Gi

部署备份

helm install --name w11backup ./charts/tidb-backup/ -f ./w11_backup.config --namespace tidb


查看job

kubectl get jobs --namespace default -l app.kubernetes.io/component=backup

查看备份信息

kubectl -n tidb get pv



kubectl -n tidb get pv local-pv-e85e3bd9 -o yaml


发现在node1上


创建crontabjob

创建root账号

kubectl --namespace tidb create secret generic backup-secret --from-literal=user=root --from-literal=password=<password>

helm inspect ./charts/tidb-cluster/

根据自身配置一下参数

binlog:

  pump:

    create: false

    replicas: 1

    image: pingcap/tidb-binlog:v2.1.0

    imagePullPolicy: IfNotPresent

    logLevel: info

    # storageClassName is a StorageClass provides a way for administrators to describe the "classes" of storage they offer.

    # different classes might map to quality-of-service levels, or to backup policies,

    # or to arbitrary policies determined by the cluster administrators.

    # refer to https://kubernetes.io/docs/concepts/storage/storage-classes

    storageClassName: local-storage

    storage: 10Gi

    # a integer value to control expiry date of the binlog data, indicates for how long (in days) the binlog data would be stored.

    # must bigger than 0

    gc: 7

    # number of seconds between heartbeat ticks (in 2 seconds)

    heartbeatInterval: 2

  drainer:

    create: false

    image: pingcap/tidb-binlog:v2.1.0

    imagePullPolicy: IfNotPresent

    logLevel: info

    # storageClassName is a StorageClass provides a way for administrators to describe the "classes" of storage they offer.

    # different classes might map to quality-of-service levels, or to backup policies,

    # or to arbitrary policies determined by the cluster administrators.

    # refer to https://kubernetes.io/docs/concepts/storage/storage-classes

    storageClassName: local-storage

    storage: 10Gi

    # parallel worker count (default 1)

    workerCount: 1

    # the interval time (in seconds) of detect pumps' status (default 10)

    detectInterval: 10

    # disbale detect causality

    disableDetect: false

    # disable dispatching sqls that in one same binlog; if set true, work-count and txn-batch would be useless

    disableDispatch: false

    # # disable sync these schema

    ignoreSchemas: "INFORMATION_SCHEMA,PERFORMANCE_SCHEMA,mysql,test"

    # if drainer donesn't have checkpoint, use initial commitTS to initial checkpoint

    initialCommitTs: 0

    # enable safe mode to make syncer reentrant

    safeMode: false

    # number of binlog events in a transaction batch (default 1)

    txnBatch: 1

    # downstream storage, equal to --dest-db-type

    # valid values are "mysql", "pb", "kafka"

    destDBType: pb

    mysql: {}

      # host: "127.0.0.1"

      # user: "root"

      # password: ""

      # port: 3306

      # # Time and size limits for flash batch write

      # timeLimit: "30s"

      # sizeLimit: "100000"

    kafka: {}

      # only need config one of zookeeper-addrs and kafka-addrs, will get kafka address if zookeeper-addrs is configed.

      # zookeeperAddrs: "127.0.0.1:2181"

      # kafkaAddrs: "127.0.0.1:9092"

      # kafkaVersion: "0.8.2.0"

scheduledBackup:

  create: false

  binlogImage: pingcap/tidb-binlog:v2.1.0

  binlogImagePullPolicy: IfNotPresent

  # https://github.com/tennix/tidb-cloud-backup

  mydumperImage: pingcap/tidb-cloud-backup:latest

  mydumperImagePullPolicy: IfNotPresent

  # storageClassName is a StorageClass provides a way for administrators to describe the "classes" of storage they offer.

  # different classes might map to quality-of-service levels, or to backup policies,

  # or to arbitrary policies determined by the cluster administrators.

  # refer to https://kubernetes.io/docs/concepts/storage/storage-classes

  storageClassName: local-storage

  storage: 100Gi

  # https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#schedule

  schedule: "0 0 * * *"

  # https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#suspend

  suspend: false

  # https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#jobs-history-limits

  successfulJobsHistoryLimit: 3

  failedJobsHistoryLimit: 1

  # https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#starting-deadline

  startingDeadlineSeconds: 3600

  # https://github.com/maxbube/mydumper/blob/master/docs/mydumper_usage.rst#options

  options: "--chunk-filesize=100"

  # secretName is the name of the secret which stores user and password used for backup

  # Note: you must give the user enough privilege to do the backup

  # you can create the secret by:

  # kubectl create secret generic backup-secret --from-literal=user=root --from-literal=password=<password>

  secretName: backup-secret

  # backup to gcp

  gcp: {}

  # bucket: ""

  # secretName is the name of the secret which stores the gcp service account credentials json file

  # The service account must have read/write permission to the above bucket.

  # Read the following document to create the service account and download the credentials file as credentials.json:

  # https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually

  # And then create the secret by: kubectl create secret generic gcp-backup-secret --from-file=./credentials.json

  # secretName: gcp-backup-secret

  # backup to ceph object storage

  ceph: {}

  # endpoint: ""

  # bucket: ""

  # secretName is the name of the secret which stores ceph object store access key and secret key

  # You can create the secret by:

  # kubectl create secret generic ceph-backup-secret --from-literal=access_key=<access-key> --from-literal=secret_key=<secret-key>

  # secretName: ceph-backup-secret

我这里配置如下:

在cluster的配置文件后面追加我们这里是w11.condig

vi ./w11.config

###

#tidb的参数忽略

###

binlog:

  pump:

    create: true

    replicas: 1

    image: pingcap/tidb-binlog:v2.1.0

    imagePullPolicy: IfNotPresent

    logLevel: info

    storageClassName: local-storage

    storage: 10Gi

    gc: 7

    heartbeatInterval: 2

  drainer:

    create: true

    image: pingcap/tidb-binlog:v2.1.0

    imagePullPolicy: IfNotPresent

    logLevel: info

    storageClassName: local-storage

    storage: 10Gi

    # parallel worker count (default 1)

    workerCount: 10

    # the interval time (in seconds) of detect pumps' status (default 10)

    detectInterval: 10

    # disbale detect causality

    disableDetect: false

    # disable dispatching sqls that in one same binlog; if set true, work-count and txn-batch would be useless

    disableDispatch: false

    # # disable sync these schema

    ignoreSchemas: "INFORMATION_SCHEMA,PERFORMANCE_SCHEMA,mysql,test"

    # if drainer donesn't have checkpoint, use initial commitTS to initial checkpoint

    initialCommitTs: 0

    # enable safe mode to make syncer reentrant

    safeMode: false

    # number of binlog events in a transaction batch (default 1)

    txnBatch: 10

    # downstream storage, equal to --dest-db-type

    # valid values are "mysql", "pb", "kafka"

    destDBType: pb

    mysql: {}

    kafka: {}

scheduledBackup:

  create: true

  binlogImage: pingcap/tidb-binlog:v2.1.0

  binlogImagePullPolicy: IfNotPresent

  mydumperImage: pingcap/tidb-cloud-backup:latest

  mydumperImagePullPolicy: IfNotPresent

  storageClassName: local-storage

  storage: 20Gi

  schedule: "0 0 * * *"


创建备份任务

helm upgrade tidb-cluster ./charts/tidb-cluster/ -f ./w11.config

kubectl get pods --namespace tidb -l app.kubernetes.io/instance=tidb-cluster -o wide

查看增量备份pump日志

kubectl --namespace tidb logs w11tidb-pump-0

查看增量备份drain的日志

kubectl --namespace tidb logs w11tidb-drainer-0

查看全量crontab

kubectl get cronjob --namespace tidb -l app.kubernetes.io/instance=tidb-cluster

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343