zoukankan      html  css  js  c++  java
  • 分享一个k8s的mysql-router配置

    因为用了k8s里搭建mysql-innodb-cluster,网上又好像没有对应mysql-router的配置,虽然也简单但能直接用最好啦,就简单修改了下弄了对应配置

    好吧,直接代码。。。

    Dockerfile(server.cicd:8089是私仓地址,自行更换呗)

    FROM server.cicd:8089/common/percona-xtrabackup:8.0
    LABEL maintainer="jiyilee"
    RUN apt-get update
    RUN apt-get  install -y net-tools
    RUN apt-get  install -y iputils-ping
    RUN apt-get purge -y percona-xtrabackup-80
    RUN apt-get update && apt-get install -y mysql-shell
    RUN apt-get install -y mysql-router
    
    EXPOSE 6446
    EXPOSE 6447
    
    CMD ["bash", "-c", "tail -f /dev/null"]

    install-router.sh(这里前提是在k8s里的mysql-service搭建好了mysql集群哦。。。好像是废话~)

    #!/usr/bin/env bash
    mysqlrouter --bootstrap root@mysql-primary-0.mysql-service:3306 -d myrouter --user=root
    
    #myrouter/start.sh
    
    #ps -ef|grep myroute
    
    #mysql -u root -h 127.0.0.1 -P 6446 -p

    deploy-mysql-router.yaml ingress-mysql-router.yaml service-nodeport.yaml(k8s文件,分三个、合一个你喜欢)

    #创建service为mysql-router
    apiVersion: v1
    kind: Service
    metadata:
      name: mysql-router
      namespace: default
    spec:
      ports:
      - name: router-port
        #targetPort: 6446
        port: 6446
      clusterIP: None
      selector:
        app: mysql-router
    ---
    #创建后端服务的pod
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mysql-router-backend-pod
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: mysql-router
      template:
        metadata:
          labels:
            app: mysql-router
        spec:
          containers:
          - name: mysql-router
            image: server.cicd:8089/common/mysql-router
            ports:
            - name: router-port
              containerPort: 6446
    ---
    apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-mysql-router namespace: default annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: mysql-router.cicd http: paths: - path: backend: serviceName: mysql-router servicePort: 6446
    ---
    apiVersion: v1 kind: Service metadata: name: mysql-router-ingress-nginx namespace: default labels: app: mysql-router spec: type: NodePort ports: - name: router-port port: 6446 targetPort: 6446 protocol: TCP nodePort: 36446 selector: app: mysql-router

    ok了, 其实整个东东很简单,当然直接mysql-router-service那type:NodePort也行。。。

    再做个mysql-router.cicd域名指向,最后就可以这样访问了

    mysql -u root -h mysql-router.cicd -P 36446 -p

    PS,还是router简单,而不是什么mycat之类。 

    若转载,请注明@jiyilee.cnblogs.com 珍惜生活,努力工作!!!
  • 相关阅读:
    Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level
    Python3 运算符
    Python3 注释
    Python3 解释器
    Python3 环境搭建
    Python 3 教程
    Python3 基本数据类型
    趣闻|Python之禅(The Zen of Python)
    ios开发笔记根据传入字符串的长度动态生成label,并按照屏幕宽度排列
    iOS开发设置tableview的分割线
  • 原文地址:https://www.cnblogs.com/jiyilee/p/13538824.html
Copyright © 2011-2022 走看看