K8S 使用Operator部署和管理TIDB

概述

tidb為分布式的newSQLdb,我們結(jié)合operator和k8s 完成tidb的部署和擴容

硬盤使用local卷,如何管理local卷請翻閱 我的另一篇文章

http://www.reibang.com/p/bfa204cef8c0

k8s機器信息 版本1.13

node1 10.16.16.119? master節(jié)點

node2 10.16.16.120 master節(jié)點

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:


指定自身參數(shù),改變指定的image,因為gcr。io國內(nèi)無法訪問

有兩種類型的存儲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即為創(chuàng)建成功

創(chuàng)建TIDB集群

查看配置參數(shù)

helm inspect charts/tidb-cluster

過多這里不在羅列积糯,主要分為

pd的設(shè)置

tidb的設(shè)置

kv的設(shè)置

monitor的設(shè)置


編寫定義參數(shù)

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


監(jiān)控為w11tidb-grafana,tidb為w11tidb-tidb

連接tidb


監(jiān)控

http://10.16.16.119:30976

密碼賬號全部 admin admin



在線擴容TIDB


編寫定義參數(shù)

將tikv 和 tidb從3個節(jié)點擴用值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/


觀察節(jié)點情況

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

兩個節(jié)點擴用中偿荷,已有節(jié)點根據(jù)情況重啟重新配置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


備份

創(chuàng)建root賬號

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


配置backup參數(shù)

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


發(fā)現(xiàn)在node1上


創(chuàng)建crontabjob

創(chuàng)建root賬號

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

helm inspect ./charts/tidb-cluster/

根據(jù)自身配置一下參數(shù)

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的參數(shù)忽略

###

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 * * *"


創(chuàng)建備份任務

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末跳纳,一起剝皮案震驚了整個濱河市忍饰,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌寺庄,老刑警劉巖艾蓝,帶你破解...
    沈念sama閱讀 206,482評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異斗塘,居然都是意外死亡赢织,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,377評論 2 382
  • 文/潘曉璐 我一進店門馍盟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來于置,“玉大人,你說我怎么就攤上這事贞岭“颂海” “怎么了搓侄?”我有些...
    開封第一講書人閱讀 152,762評論 0 342
  • 文/不壞的土叔 我叫張陵,是天一觀的道長话速。 經(jīng)常有香客問我讶踪,道長,這世上最難降的妖魔是什么泊交? 我笑而不...
    開封第一講書人閱讀 55,273評論 1 279
  • 正文 為了忘掉前任乳讥,我火速辦了婚禮,結(jié)果婚禮上廓俭,老公的妹妹穿的比我還像新娘云石。我一直安慰自己,他們只是感情好研乒,可當我...
    茶點故事閱讀 64,289評論 5 373
  • 文/花漫 我一把揭開白布留晚。 她就那樣靜靜地躺著,像睡著了一般告嘲。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上奖地,一...
    開封第一講書人閱讀 49,046評論 1 285
  • 那天橄唬,我揣著相機與錄音,去河邊找鬼参歹。 笑死仰楚,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的犬庇。 我是一名探鬼主播僧界,決...
    沈念sama閱讀 38,351評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼臭挽!你這毒婦竟也來了捂襟?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,988評論 0 259
  • 序言:老撾萬榮一對情侶失蹤欢峰,失蹤者是張志新(化名)和其女友劉穎葬荷,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體纽帖,經(jīng)...
    沈念sama閱讀 43,476評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡宠漩,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,948評論 2 324
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了懊直。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片扒吁。...
    茶點故事閱讀 38,064評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖室囊,靈堂內(nèi)的尸體忽然破棺而出雕崩,到底是詐尸還是另有隱情魁索,我是刑警寧澤,帶...
    沈念sama閱讀 33,712評論 4 323
  • 正文 年R本政府宣布晨逝,位于F島的核電站蛾默,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏捉貌。R本人自食惡果不足惜支鸡,卻給世界環(huán)境...
    茶點故事閱讀 39,261評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望趁窃。 院中可真熱鬧牧挣,春花似錦、人聲如沸醒陆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,264評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽刨摩。三九已至寺晌,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間澡刹,已是汗流浹背呻征。 一陣腳步聲響...
    開封第一講書人閱讀 31,486評論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留罢浇,地道東北人陆赋。 一個月前我還...
    沈念sama閱讀 45,511評論 2 354
  • 正文 我出身青樓,卻偏偏與公主長得像嚷闭,于是被迫代替她去往敵國和親攒岛。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 42,802評論 2 345