k8s集群通过nginx-ingress做tcpudp 4层网络转发

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s集群通过nginx-ingress做tcpudp 4层网络转发相关的知识,希望对你有一定的参考价值。

k8s集群可以通过nginx-ingress做tcp\\udp 4层网络转发

1.先确认K8S集群是否开启tcp/udp

[root@k8s-master-pro01 tmp]# kubectl get cm -n ingress-nginx 
NAME DATA AGE
ingress-controller-leader-nginx 0 18h
ingress-nginx-controller 0 18h
kube-root-ca.crt 1 18h
tcp-services 1 18h
udp-services 1 18h

2.确认已经开启后,修改tcp-services 和udp-services  的cm

  我的环境需要增加多个tcp胡端口分别为6622/6620/6621/2001

kubectl edit cm tcp-services -n ingress-nginx 
apiVersion: v1
data:
"6622": prod/tgs2:6622
"6621": prod/tgs2:6621
"6620": prod/tgs2:6620
"2001": prod/tgs2:2001
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
"apiVersion":"v1","kind":"ConfigMap","metadata":"annotations":,"name":"tcp-services","namespace":"ingress-nginx"
creationTimestamp: "2022-11-15T07:54:20Z"
name: tcp-services
namespace: ingress-nginx
resourceVersion: "194865"

此时进入ingress-nginx的pod再去看nginx的conf就可以看到新增的端口

bash-5.1$ cat nginx.conf|grep 6622
ngx.var.proxy_upstream_name="tcp-prod-tgs2-6622";
listen 6622;
listen [::]:6622;
bash-5.1$ cat nginx.conf|grep 6621
ngx.var.proxy_upstream_name="tcp-prod-tgs2-6621";
listen 6621;
listen [::]:6621;
bash-5.1$ cat nginx.conf|grep 6622
ngx.var.proxy_upstream_name="tcp-prod-tgs2-6622";
listen 6622;
listen [::]:6622;
bash-5.1$ cat nginx.conf|grep 2001
ngx.var.proxy_upstream_name="tcp-prod-tgs2-2001";
listen 2001;
listen [::]:2001;

udp同理操作


此时网页打开测试:

k8s集群通过nginx-ingress做tcp\\udp

以上是关于k8s集群通过nginx-ingress做tcpudp 4层网络转发的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 nginx-ingress 控制器通过 TCP 公开多个服务?

用于 websocket 应用程序的 nginx-ingress 粘性会话

k8s Nginx-ingress配置https

[k8s]nginx-ingress配置4/7层测试

如何使用一个负载均衡器为两个域的两个入口配置 nginx-ingress

Rook Ceph Operator 在检查集群状态时挂起