简体   繁体   English

如何从客户端访问使用 Nginx Ingress+Kubernetes 托管的 MySql

[英]How to access MySql hosted with Nginx Ingress+Kubernetes from client

I am new to Kubernetes and Nginx Ingress tools and now i am trying to host MySql service using VHost in Nginx Ingress on AWS.我是 Kubernetes 和 Nginx Ingress 工具的新手,现在我尝试在 AWS 上的 Nginx Ingress 中使用 VHost 托管 MySql 服务。 I have created a file something like :我创建了一个类似的文件:

apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  type: NodePort
  ports:
    - port: 3306
      protocol: TCP
  selector:
    app: mysql
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql
          imagePullPolicy: IfNotPresent
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: password
          ports:
            - name: http
              containerPort: 3306
              protocol: TCP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mysql
  labels:
    app: mysql
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: mysql.example.com
      http:
        paths:
          - path: /
            backend:
              serviceName: mysql
              servicePort: 3306

My LoadBalancer (created by Nginx Ingress) port configuration looks like :我的 LoadBalancer(由 Nginx Ingress 创建)端口配置如下所示:

80 (TCP) forwarding to 32078 (TCP)
Stickiness options not available for TCP protocols

443 (TCP) forwarding to 31480 (TCP)
Stickiness options not available for TCP protocols

mysql.example.com is pointing to my ELB. mysql.example.com指向我的 ELB。

I was expecting something like, from my local box i can connect to MySql if try something like :我期待着类似的东西,如果尝试以下操作,我可以从我的本地盒子连接到 MySql:

mysql -h mysql.example.com -u root -P 80 -p

Which is not working out.这是行不通的。 Instead of NodePort if i try with LoadBalancer , its creating a new ELB for me which is working as expected.如果我尝试使用LoadBalancer而不是NodePort ,它会为我创建一个按预期工作的新 ELB。

I am not sure if this is right approach for what i want to achieve here.我不确定这是否是我想在这里实现的正确方法。 Please help me out if there is a way for achieving same using the Ingress with NodePort.如果有办法使用带有 NodePort 的 Ingress 实现相同的目标,请帮助我。

Kubernetes Ingress as a generic concept does not solve the issue of exposing/routing TCP/UDP services, as stated in https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md you should use custom configmaps if you want that with ingress. Kubernetes Ingress 作为一个通用概念并没有解决暴露/路由 TCP/UDP 服务的问题,如https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp 中所述-udp-services.md如果您希望使用 ingress,您应该使用自定义配置映射 And please mind that it will never use hostname for routing as that is a feature of HTTP, not TCP.请注意,它永远不会使用主机名进行路由,因为这是 HTTP 的功能,而不是 TCP。

I succeded to access MariaDB/MySQL hosted on Google Kubernetes Engine through ingress-nginx, using the hostname specified in the ingress created for the database Cluster IP.我成功地通过 ingress-nginx 访问了托管在 Google Kubernetes Engine 上的 MariaDB/MySQL,使用在为数据库集群 IP 创建的入口中指定的主机名。

As per the docs , simply create the config map and expose the port in the Service defined for the Ingress.根据文档,只需创建配置映射并在为 Ingress 定义的服务中公开端口。

This helped me to figure how to set --tcp-services-configmap and --udp-services-configmap flags. 帮助我弄清楚如何设置--tcp-services-configmap--udp-services-configmap标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM