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

Vivek Kumar picture Vivek Kumar · Feb 14, 2018 · Viewed 8k times · Source

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. 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 :

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.

I was expecting something like, from my local box i can connect to MySql if try something like :

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.

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.

Answer

Radek 'Goblin' Pieczonka picture Radek 'Goblin' Pieczonka · Feb 14, 2018

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. And please mind that it will never use hostname for routing as that is a feature of HTTP, not TCP.