作者:李毓

约定:
k8s:1.18
helm:v3
mysql:5.7.13
ceph:rbd模式

按照之前的教程,先添加好仓库

[root@adm-master ~]# helm repo listNAME        URL                                                   charts      https://kubernetes.oss-cn-hangzhou.aliyuncs.com/chartsstable      http://mirror.azure.cn/kubernetes/charts              aliyuncs    https://apphub.aliyuncs.com        
[root@adm-master ~]# helm pull aliyuncs/mysqlha[root@adm-master ~]# tar -zxvf mysqlha-1.0.0.tgz[root@adm-master mysqlha]# lsChart.yaml  OWNERS  README.md  templates  values.yaml

官方的模板里面有个坑

这里原本是没有的,要给他加上。

[root@adm-master mysqlha]# vim templates/statefulset.yaml apiVersion: apps/v1kind: StatefulSetmetadata:  name: {{ template "fullname" . }}  labels:    app: {{ template "fullname" . }}    chart: "{{ template "mysqlha.chart" . }}"    release: "{{ .Release.Name }}"    heritage: "{{ .Release.Service }}"spec:  serviceName: {{ template "fullname" . }}  replicas: {{ .Values.mysqlha.replicaCount }}  selector:    matchLabels:      app: {{ template "fullname" . }}

执行命令

[root@adm-master mysqlha]# helm install mysql . -f ./values.yamlNAME: mysqlLAST DEPLOYED: Sat Mar 20 20:54:20 2021NAMESPACE: defaultSTATUS: deployedREVISION: 1TEST SUITE: NoneNOTES:The MySQL cluster is comprised of 3 MySQL pods: 1 master and 2 slaves. Each instance is accessible within the cluster through:    <pod-name>.mysql-mysqlha`mysql-mysqlha-0.mysql-mysqlha` is designated as the master and where all writes should be executed against. Read queries can be executed against the `mysql-mysqlha-readonly` service which distributes connections across all MySQL pods.To connect to your database:1. Obtain the root password:     kubectl get secret --namespace default mysql-mysqlha -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo2. Run a pod to use as a client:    kubectl run mysql-client --image=mysql:5.7.13 -it --rm --restart='Never' --namespace default -- /bin/sh3. To connect to Master service (read/write):    mysql -h mysql-mysqlha-0.mysql-mysqlha -u root -p4. To connect to slave service (read-only):   mysql -h mysql-mysqlha-readonly -u root -p

有必要验证一下读写分离

先获取密码

进行base64反编码

[root@adm-master mysqlha]# echo -n MjIzRjBNTkFFV2hh | base64 --decode223F0MNAEWha[root@adm-master mysqlha]# echo -n a3FOdzZUbktGVjNq | base64 --decodekqNw6TnKFV3j

进入容器

[root@adm-master mysqlha]# kubectl get pods -o wideNAME                                     READY   STATUS    RESTARTS   AGE    IP             NODE        NOMINATED NODE   READINESS GATESmysql-mysqlha-0                          2/2     Running   0          31m    10.244.2.227   adm-node2   <none>           <none>mysql-mysqlha-1                          2/2     Running   0          30m    10.244.1.193   adm-node1   <none>           <none>mysql-mysqlha-2                          2/2     Running   0          29m    10.244.2.228   adm-node2   <none>           <none>nfs-client-provisioner-cc544b949-k8n2s   1/1     Running   29         109d   10.244.1.186   adm-node1   <none>           <none>rbd-provisioner-c968dcb4b-wbhlc          1/1     Running   1          26h    10.244.1.187   adm-node1   <none>           <none>[root@adm-master mysqlha]# kubectl exec -it mysql-mysqlha-0 shkubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.Defaulting container name to mysql.Use 'kubectl describe pod/mysql-mysqlha-0 -n default' to see all of the containers in this pod.# # mysql -h10.244.2.227 -uroot -pkqNw6TnKFV3jmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 203Server version: 5.7.13-log MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

创建数据

mysql> show databases;+------------------------+| Database               |+------------------------+| information_schema     || mysql                  || performance_schema     || sys                    || xtrabackup_backupfiles |+------------------------+5 rows in set (0.00 sec)mysql> CREATE DATABASE test;Query OK, 1 row affected (0.02 sec)mysql> CREATE TABLE test.messages (message VARCHAR(250));Query OK, 0 rows affected (0.06 sec)mysql> INSERT INTO test.messages VALUES ('hello');Query OK, 1 row affected (0.02 sec)mysql> show databases;+------------------------+| Database               |+------------------------+| information_schema     || mysql                  || performance_schema     || sys                    || test                   || xtrabackup_backupfiles |+------------------------+6 rows in set (0.00 sec)mysql> use test;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> select * from messages;+---------+| message |+---------+| hello   |+---------+1 row in set (0.00 sec)

# mysql -uroot -h10.1.195.242 -pkqNw6TnKFV3jmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 265Server version: 5.7.13 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases ;+------------------------+| Database               |+------------------------+| information_schema     || mysql                  || performance_schema     || sys                    || test                   || xtrabackup_backupfiles |+------------------------+6 rows in set (0.01 sec)
©著作权归作者所有:来自51CTO博客作者木子每旒的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 干货!MySql DAL中间件总结
  2. 微软被指剽窃他人开源作品!作者被迫终止该项目
  3. 上万字详解Spark Core(建议收藏)
  4. 一个数据工作者的自白
  5. 又一个程序员“倒”下,Pandownload作者被抓
  6. 重要 | mr使用hcatalog读写hive表
  7. 无法定位程序输入点ucrtbase.terminate于动态链接库api-ms-win-c
  8. Kafka源码系列之kafka如何实现高性能读写的
  9. idea激活码_idea激活码2021_idea激活码2020_idea激活码2018,最新

随机推荐

  1. 通过xml加载菜单Menus
  2. Android图形系统分析与移植--五、Android
  3. android设置在ListView中让TextView滚动
  4. Android 源代码结构
  5. android 电容屏(一):电容屏基本原理篇
  6. android:gravity 和 android:layout_Grav
  7. android图片涂鸦,具有设置画笔,撤销,缩放移
  8. Android(安卓)学习笔记 ——第二行代码
  9. Android使用AudioRecord遇到的问题与解决
  10. Android ANR问题分析思路