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

相关推荐
LaoZhangGong12319 小时前
学习TCP/IP的第1步:ARP数据包
网络·stm32·学习·tcp/ip·以太网·arp·uip
LaoZhangGong12320 小时前
学习TCP/IP的第2步:ICMP数据包
网络·网络协议·学习·tcp/ip·以太网
上海云盾安全满满20 小时前
高防IP如何实现为数藏精准防刷策略
网络·tcp/ip·安全
一勺菠萝丶20 小时前
芋道项目部署:前端写死后端地址 vs Nginx 反向代理
前端·nginx·状态模式
✧˖‹gσσ∂ иιghт›✧21 小时前
esp32 s3 修改本地ip和服务器IP
服务器·网络协议·tcp/ip
qq_4112624221 小时前
优化wifi的性能,LWIP_TCP_WND是不是指的是DYNAMIC_RX_BUFFER动态接受缓冲区的缓冲区大小
网络·网络协议·tcp/ip
阿杰 AJie21 小时前
如何将公司公网ip绑定到服务器和域名
服务器·网络·tcp/ip
阿巴~阿巴~1 天前
从帧到包:深入解析链路层与局域网通信的核心机制
服务器·网络·网络协议·tcp/ip·智能路由器·mac·数据链路层
科技块儿1 天前
金融级IP离线库深度测评:IP数据云 vs IPnews vs MaxMind
网络协议·tcp/ip·金融
funnycoffee1231 天前
F5 Big IP如何设置web和SSH登录的白名单
前端·tcp/ip·ssh