How to use nginx ingress TCP service on different namespace [duplicate]

感情迁移 提交于 2019-12-08 13:02:28

问题


I have deployed two namespace in the kubernetes cluster. The namespace A host mysql and namespace B run postgress and expose their service deployment on these ports

Namespace(A) - mysql - port (3306)
Namespace(B) - postgress - port (5432)

I need to use nginx-ingress kubernetes cluster to route the traffic based, here is the sample YAML file for the ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mysql-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: mysql-ingress
    http:
      paths:
      - path: /mysql
        backend:
          serviceName: mysql
          servicePort: 3306

This YAML file is more suitable for HTTP kind of service, How to achieve the TCP service using nginx-ingress


回答1:


You can refer to the following document to expose tcp and udp services.

https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md

In my cluster, the ingress controller is installed on ingress-nginx namespace. You can get the tcp service from configmap.

kubectl get cm -n ingress-nginx tcp-services -o yaml

Basically, you just specify the service for your two databases.

data:
  "3306": NamespaceA/mysql:3306
  "5432": NamespaceB/postgress:5432


来源:https://stackoverflow.com/questions/57301394/how-to-use-nginx-ingress-tcp-service-on-different-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!