因为用了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之类。 

posted on 2020-08-21 00:15  记忆  阅读(1427)  评论(0编辑  收藏  举报
有我在,可保你IT无忧!