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

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: replication120 ## MySQL Authentication parameters121 ##122 auth:123   ## @param auth.rootPassword Password for the `root` user. Ignored if existing secret is provided124   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#setting-the-root-password-on-first-run125   ##126   rootPassword: "abc123456"127   ## @param auth.createDatabase Whether to create the .Values.auth.database or not128   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-on-first-run129   ##130   createDatabase: true131   ## @param auth.database Name for a custom database to create132   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-on-first-run133   ##134   database: "my_database"135   ## @param auth.username Name for a custom user to create136   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-user-on-first-run137   ##138   username: ""139   ## @param auth.password Password for the new user. Ignored if existing secret is provided140   ##141   password: ""142   ## @param auth.replicationUser MySQL replication user143   ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#setting-up-a-replication-cluster144   ##145   replicationUser: replicator146   ## @param auth.replicationPassword MySQL replication user password. Ignored if existing secret is provided147   ##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   20hNAME                                 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          73mNAME                               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-servicesnamespace: ingress-nginx
data:"30306": "mysql/mysql-primary:3306""30307": "mysql/mysql-secondary:3306"

应用configmap

kubectl apply -f mysql-tcp-cm.yaml

四、测试连接

 

http://www.lryc.cn/news/524619.html

相关文章:

  • 麒麟操作系统服务架构保姆级教程(十三)tomcat环境安装以及LNMT架构
  • 亚博microros小车-原生ubuntu支持系列:4-手部检测
  • 关于回调函数(callback)
  • Linux Bash 中使用重定向运算符的 5 种方法
  • 硬件作品3----STM32F103RCT6最小系统板MCU配置
  • 人脸识别打卡系统--基于QT(附源码)
  • 【深度学习入门】深度学习知识点总结
  • 通过视觉语言模型蒸馏进行 3D 形状零件分割
  • 机器学习10-解读CNN代码Pytorch版
  • 微服务学习-Gateway 统一微服务入口
  • 2025寒假备战蓝桥杯02---朴素二分查找升级版本的学习+分别求解左右端点
  • PHP语言的软件工程
  • linux-FTP服务配置与应用
  • 靠右行驶数学建模分析(2014MCM美赛A题)
  • (1)STM32 USB设备开发-基础知识
  • Spring中如何动态的创建、监听MQ以及创建Exchange
  • 中国综合算力指数(2024年)报告汇总PDF洞察(附原数据表)
  • 【Python项目】小区监控图像拼接系统
  • 常用排序算法之插入排序
  • Elasticsearch(ES)基础查询语法的使用
  • 一篇文章学会Milvus【Docker 中运行 Milvus(Windows),Python实现对Milvus的操作,源代码案例,已经解决巨坑】【程序员猫爪】
  • 前端之移动端
  • 记一次 SpringBoot 启动慢的问题
  • 高效安全文件传输新选择!群晖NAS如何实现无公网IP下的SFTP远程连接
  • 如何在Python中进行JSON数据的序列化和反序列化?
  • 学习记录-统计记录场景下的Redis写请求合并优化实践
  • 网站HTTP改成HTTPS
  • 如何在龙蜥 OS(AliOS)上安装极狐GitLab?
  • unity插件Excel转换Proto插件-ExcelToProtobufferTool
  • C#中的语句