You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Kubernetes的Nginx Ingress Controller添加9898监听端口

给Nginx Ingress Controller添加9898端口监听的解决步骤
  • 确认DaemonSet端口配置
    先检查DaemonSet的容器端口映射是否正确配置,需同时设置containerPort和hostPort,确保协议匹配(默认TCP)。示例配置片段:

    ports:
      - name: http
        containerPort: 80
        hostPort: 80
        protocol: TCP
      - name: https
        containerPort: 443
        hostPort: 443
        protocol: TCP
      - name: custom-9898
        containerPort: 9898
        hostPort: 9898
        protocol: TCP
    

    注意:9898属于1024以上端口,无需额外特权权限。

  • 修改Nginx配置模板
    仅修改DaemonSet端口没用,必须让Nginx本身监听9898端口:

    1. 找到Ingress Controller对应的ConfigMap(通常命名为nginx-ingress-controller),编辑其中的nginx.conf模板。
    2. 添加监听9898的server块,示例如下:
      server {
        listen 9898;
        server_name _;
      
        location / {
          # 替换为你的上游服务配置,或复用80端口的转发规则
          proxy_pass http://your-target-service;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
        }
      }
      

    若用Helm部署,可直接修改values.yaml中的controller.config或添加controller.extraArgs来注入自定义配置。

  • 重启Ingress Controller Pod
    配置修改后需重启Pod让生效:

    kubectl rollout restart daemonset <nginx-ingress-daemonset-name> -n <your-namespace>
    

    或者直接删除Pod触发重建:

    kubectl delete pod -l app=nginx-ingress -n <your-namespace>
    
  • 验证配置生效

    • 进入Pod内部检查端口监听:
      kubectl exec -it <pod-name> -n <your-namespace> -- netstat -tulpn | grep 9898
      
    • 在节点上检查主机端口映射:
      netstat -tulpn | grep 9898
      
    • 用curl测试端口连通性:
      curl http://<node-ip>:9898
      

内容的提问来源于stack exchange,提问作者Iceforest

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 14:45:25