Nginx-Ingress-Controller自定义端口实现TCP/UDP转发

背景1

使用deployment部署一个http服务,配合使用ingress+tls的解析在ingress终止。

复制代码
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
  name: test.com
  namespace: rcs-netswitch-prod
spec:
  defaultBackend:
    service:
      name: rcs-netswitch-prod
      port:
        number: 9200
  ingressClassName: nginx
  rules:
    - host: test.com
      http:
        paths:
          - backend:
              service:
                name: rcs-netswitch-prod
                port:
                  number: 9200
            path: /
            pathType: Prefix
  tls:
    - hosts:
        - test.com
      secretName: test.com

访问https://test.com:443结果请求正常。

去除tls部分的配置http://test.com:80也正常

背景2

使用deployment部署一个http服务,配合使用ingress+tls的解析在ingress终止,使用非443和80端口配置

需要在nginx-ingress-controller开启tcp/udp支持。启动参数确保有--tcp-services-configmap=xxx,如果没有,手动添加

  • '--tcp-services-configmap=$(POD_NAMESPACE)/nginx-ingress-tcp'

二、添加对应configmap nginx-ingress-tcp

复制代码
apiVersion: v1
data:
  "9200": test-devops/nacos-headless:9200
kind: ConfigMap
metadata:
  name: nginx-ingress-tcp
  namespace: ingress-nginx

格式:"端口": 命名空间/服务:端口

前面的端口是nginx-ingress-controller监听端口,会转发到命名空间下的服务:端口

复制代码
          ports:
            - containerPort: 80
              hostPort: 80
              name: http
              protocol: TCP
            - containerPort: 443
              hostPort: 443
              name: https
              protocol: TCP

这里是通过hostPort方式映射的端口,也可以在service中使用loadBalance、nodePort方式暴露端口,nodePort方式还需要添加LB转发

参考链接:https://blog.csdn.net/biyanjiangdu04942/article/details/145324374

相关推荐
国际云,接待32 分钟前
Nginx 后面接负载均衡,502/504 到底该先查哪里?
运维·nginx·负载均衡
xbakbio_z40 分钟前
尿苷二磷酸氨基葡萄糖cas17479-04-8,UDP-GIcNH2/UDP-GlcN,UDP-氨基葡萄糖的化学结构
udp·糖化学·氨基葡萄糖·核苷酸糖·cas17479-04-8
二宝哥3 小时前
CentOS 7.9 离线安装 Nginx 并配置openssl1.1.1
linux·nginx·centos
Bobolink_4 小时前
IP更换频率:账号运营里多久换一次IP算正常
大数据·网络协议·tcp/ip
treesforest5 小时前
你的IP干净吗?
网络·网络协议·tcp/ip·跨境电商·ip归属地查询·跨境
llllll1525 小时前
深入浅出计算机网络:从 TCP 可靠传输到 DNS 解析核心原理
网络协议·tcp/ip·计算机网络
March.s5 小时前
Nginx 服务器反向代理实战指南
服务器·nginx·github
峥无6 小时前
《TCP/IP协议栈详解:协议分层·封装分用·地址管理》
网络·网络协议·tcp/ip
GDAL16 小时前
Nginx TCP/UDP四层转发(Stream模块)完整深入教程
tcp/ip·nginx·udp
夏雪coding1 天前
nginx SPA 回落把 CSS 变成了 HTML:一个返回 200 却让样式失效的坑
前端·nginx