MySQL InnodbCluster(Kubernetes部署
2021-12-08 本文已影响0人
onmeiei
下载crd定义
下载mysql innodbcluster crd定义 - deploy-crds.yaml
下载mysql operator定义 - deploy-operator.yaml
下载完毕后,执行
$ kubectl apply -f deploy-crds.yaml
$ kubectl apply -f deploy-operator.yaml
创建本地PV存储
本地PV存储需要创建多个,以一主二从为例,则需要创建三个,在pv目录中新建三个pv-xxxxx.yaml,以其中一个为例:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-mysql-lthpc
labels:
# 重要,innodb选择pv时使用
pv: pv-mysql
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
# 实际存储路径
path: /k8s-pv/mysql
nodeAffinity:
required:
# 选择分配的节点
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- lthpc
通过以下命令进行创建:
$ kubectl apply -f pv/
创建innodb cluster集群,一主二从
innodbcluster集群定义文件mysql-cluster.yaml
的内容如下:
apiVersion: v1
kind: Namespace
metadata:
name: database
---
apiVersion: v1
data:
# root授权的host,此处为“%”
rootHost: JQ==
# root的密码,此处为“mypass”
rootPassword: bXlwYXNzCg==
# root的用户名,此处为“root”
rootUser: cm9vdA==
kind: Secret
metadata:
name: mypwds
namespace: database
---
apiVersion: mysql.oracle.com/v2alpha1
kind: InnoDBCluster
metadata:
name: mysql-cluster
namespace: database
spec:
secretName: mypwds
# mysql innodb 节点数目,3个,一个主节点,两个从节点
instances: 3
# router的个数,访问时访问router的service端口即可
router:
instances: 1
datadirVolumeClaimTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: 'local-storage'
selector:
# 和PV声明中的labels对应
matchLabels:
pv: pv-mysql
执行如下命令:
$ kubectl apply -f mysql-cluster.yaml
总结
operator真的让运维人员省去了很多部署麻烦,当然有些参数的优化还是比较复杂的。