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

相关推荐
MrSYJ4 天前
TCP协议理解
后端·tcp/ip
Avan_菜菜8 天前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
ping某12 天前
为什么 Nginx 明明监听了 80,转发后端时却用了 4xxxx 端口?
后端·nginx
treesforest14 天前
AI安全系统如何识别异常访问?IP风险识别正在成为关键能力
网络·人工智能·tcp/ip·安全·web安全
江华森15 天前
TCP/IP 协议栈实战 — 7 个实验详解
网络·tcp/ip·智能路由器
難釋懷15 天前
Nginx反向代理中的容错机制
运维·nginx
bloglin9999915 天前
Nginx高危漏洞CVE-2021-23017及配置样例
运维·nginx
进阶的小名15 天前
Spring Boot SSE + Nginx 配置:解决 EventSource 不实时返回、连接超时、流式响应被缓冲问题
spring boot·后端·nginx
酉鬼女又兒15 天前
零基础入门计算机网络运输层:端到端通信核心作用、端口号分类规则、复用分用工作机制及UDP与TCP协议全方位对比详解
网络·网络协议·tcp/ip·计算机网络·考研·udp·php
dog25015 天前
不要再继续优化 TCP
网络协议·tcp/ip·php