如何在不同的命名空间上使用Nginx入口TCP服务 [英] How to use nginx ingress TCP service on different namespace
问题描述
我在kubernetes集群中部署了两个名称空间.命名空间A主机mysql和命名空间B运行postgress并在这些端口上公开其服务部署
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)
我需要使用nginx-ingress kubernetes集群来路由流量,这是入口的示例YAML文件
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
此YAML文件更适合HTTP服务,如何使用nginx-ingress实现TCP服务
This YAML file is more suitable for HTTP kind of service, How to achieve the TCP service using nginx-ingress
推荐答案
您可以参考以下文档来公开tcp和udp服务.
You can refer to the following document to expose tcp and udp services.
https ://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposed-tcp-udp-services.md
在我的集群中,入口控制器安装在ingress-nginx名称空间上.您可以从configmap获取tcp服务.
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
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
这篇关于如何在不同的命名空间上使用Nginx入口TCP服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!