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同理操作
此时网页打开测试:
标签:ingress,udp,tcp,tgs2,nginx,prod,6622,listen From: https://blog.51cto.com/u_13963804/5855083