当前位置: 首页 > article >正文

ingress-nginx代理tcp使其能外部访问mysql

一、helm部署mysql主从复制

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

 

helm pull bitnami/mysql

 解压后编辑values.yaml文件,修改如下(storageclass已设置默认类)

 117 ## @param architecture MySQL architecture (`standalone` or `replication`)
 118 ##
 119 architecture: replication
 120 ## MySQL Authentication parameters
 121 ##
 122 auth:
 123   ## @param auth.rootPassword Password for the `root` user. Ignored if existing secret is provided
 124   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#setting-the-root-password-on-first-run
 125   ##
 126   rootPassword: "abc123456"
 127   ## @param auth.createDatabase Whether to create the .Values.auth.database or not
 128   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-on-first-run
 129   ##
 130   createDatabase: true
 131   ## @param auth.database Name for a custom database to create
 132   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-on-first-run
 133   ##
 134   database: "my_database"
 135   ## @param auth.username Name for a custom user to create
 136   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-user-on-first-run
 137   ##
 138   username: ""
 139   ## @param auth.password Password for the new user. Ignored if existing secret is provided
 140   ##
 141   password: ""
 142   ## @param auth.replicationUser MySQL replication user
 143   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#setting-up-a-replication-cluster
 144   ##
 145   replicationUser: replicator
 146   ## @param auth.replicationPassword MySQL replication user password. Ignored if existing secret is provided
 147   ##
 148   replicationPassword: "abc123456"

安装

helm install mysql ./mysql -n mysql --create-namespace

 

二、添加ingress控制器tcp配置

[root@k8s-master01 mysql]# kubectl get daemonset,pods -n ingress-nginx
NAME                                      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR                         AGE
daemonset.apps/ingress-nginx-controller   1         1         1       1            1           ingress=true,kubernetes.io/os=linux   20h

NAME                                 READY   STATUS    RESTARTS   AGE
pod/ingress-nginx-controller-xcn5q   1/1     Running   0          9m46s

这里使用的是daemonset方式部署的,如果是deployment,需要将daemonset修改成deployment

kubectl edit daemonset ingress-nginx-controller -n ingress-nginx

 添加tcp配置

- --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services

三、编写相应的configmap

查看当前mysql服务

[root@k8s-master01 mysql]# kubectl get pods,svc -n mysql
NAME                    READY   STATUS    RESTARTS   AGE
pod/mysql-primary-0     1/1     Running   0          73m
pod/mysql-secondary-0   1/1     Running   0          73m

NAME                               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/mysql-primary              ClusterIP   10.102.29.24    <none>        3306/TCP   73m
service/mysql-primary-headless     ClusterIP   None            <none>        3306/TCP   73m
service/mysql-secondary            ClusterIP   10.106.87.104   <none>        3306/TCP   73m
service/mysql-secondary-headless   ClusterIP   None            <none>        3306/TCP   73m

 编写configmap,注意当前namespace为mysql

vim mysql-tcp-cm.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  "30306": "mysql/mysql-primary:3306"
  "30307": "mysql/mysql-secondary:3306"

应用configmap

kubectl apply -f mysql-tcp-cm.yaml

四、测试连接

 


http://www.kler.cn/a/511370.html

相关文章:

  • Flowable 管理各业务流程:流程设计器 (获取流程模型 XML)、流程部署、启动流程、流程审批、流程挂起和激活、任务分配
  • 天机学堂5-XxlJobRedis
  • 【蜂巢——方向,数学】
  • 如何使用C#与SQL Server数据库进行交互
  • 初学stm32 --- CAN
  • Qt之文件系统操作和读写
  • reac 后端接口返回二进制文件流前端导出文件
  • 主控制器与子模块通讯协议
  • 要获取本地的公网 IP 地址(curl ifconfig.me)
  • 【Compose multiplatform教程】05 IOS环境编译
  • Linux(DISK:raid5、LVM逻辑卷)
  • 基于GRU实现股价多变量时间序列预测(PyTorch版)
  • 数据结构-顺序表链表经典OJ题
  • RabbitMQ集群安装rabbitmq_delayed_message_exchange
  • 【数据库知识】PostgreSQL介绍
  • 学英语学技术: jmeter插件管理器
  • nginx 配置防爬虫
  • 83.删除排序链表中的重复元素 python
  • sqlfather笔记
  • DQN【算法+代码】玩openai gym库游戏
  • 创建react18版本脚手架报错
  • SparseInst实例测试(含cuda10.1、pytorch1.8、detectron2安装过程)
  • C#中的语句
  • 【HTTP】详解
  • STL--set(集合)
  • 一文大白话讲清楚webpack基本使用——2——css相关loader的配置和使用