Oracle MySQL Operator 集群维护
架构
部署过程
- 1、CRD
- 2、Operator Deployment
- 3、InnodbCluster CR
实例
apiVersion: v1
kind: Secret
metadata:
name: mysql
stringData:
rootUser: root
rootHost: '%'
rootPassword: 123456
---
apiVersion: mysql.oracle.com/v2
kind: InnoDBCluster
metadata:
name: mysql
spec:
secretName: mysql
imageRepository: hub.geovis.com.cn/library
tlsUseSelfSigned: true
instances: 3
router:
instances: 3
datadirVolumeClaimTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
mycnf: |
[mysqld]
authentication_policy=mysql_native_password
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
secure-file-priv=/var/lib/mysql-files
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
explicit_defaults_for_timestamp
max_allowed_packet=16M
bind-address=0.0.0.0
character-set-server=UTF8MB4
collation-server=utf8mb4_unicode_ci
lower_case_table_names=1
max_connections=100000
wait_timeout=86400
innodb_thread_sleep_delay=10000
interactive_timeout=7200
default-time_zone='+8:00'
查看 operator 日志
kubectl -n mysql-operator logs -f $(kubectl get pod -n mysql-operator -l name=mysql-operator -o jsonpath='{.items[0].metadata.name}')
查看 innodbcluster 状态
kubectl get innodbcluster --watch
删除出问题的 Pod (尽量避免直接删除 Pod)
kubectl delete pod mysql-cluster-2
kubectl delete pod mysql-cluster-2 --force --grace-period=0
kubectl patch pod/mysql-cluster-2 -p '{"metadata":{"finalizers":[]}}' --type=merge
尝试重启 router
kubectl -n mysql-operator delete pod -l name=mysql-operator
Service
不同的 Service 有不同的用途
{cluster-name}.{namespace}.svc.{cluster-name} 为 ClusterIP,负载到所有 Router,用于集群访问
{cluster-name}-instances.{namespace}.svc.{cluster-name} 为 Headless Service,负载到所有 MySQL-Server 的 Pod,用于管理、监控等用途
端口
InnodbCluster 使用不同端口实现读写分离等
mysql: 3306
mysqlx: 33060
mysql-alternate: 6446
mysqlx-alternate: 6448
mysql-ro: 6446
mysql-rx: 6447
mysqlx-ro: 6448
mysqlx-rw: 6449
注意事项
应尽量避免直接操作 StatefulSet、Secret、ConfigMap、Service、Deployment 等资源,使用 InnodbCluster 进行扩缩容等管理操作
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 套陆的博客!
评论
TwikooUtterances