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

Kubernetes Ingress 80端口无法连接问题排查求助

问题排查:Ingress 80端口无法访问

预期流量路径

client ---> Ingress (SSL,LoadBalancer) ---> my_web(service) -> PODs

Ingress配置

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo

spec:
  ingressClassName: nginx

  rules:
    - host: "test.foo.com"
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: my_web
                port:
                  number: 8080

问题现象

执行 curl http://test.foo.com:80 时无法建立连接。

已验证信息

  • 已在hosts文件中将 test.foo.com 映射至 127.0.0.1
  • 直接访问my_web服务(LoadBalancer类型)正常:curl http://localhost:8080 返回成功

疑问

Ingress是否对外暴露了80端口?

my_web服务配置(my_web_service.yaml)

apiVersion: v1
kind: Service
metadata:
  name: my_web
  labels:
    app: my_web
spec:
  ports:
    - name: http
      port: 8080
      targetPort: 8080
  selector:
    app: my_web
  type: LoadBalancer

my_web部署配置(my_web_deployment.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my_web
  labels:
    app: my_web
spec:
  selector:
    matchLabels:
      app: my_web
  template:
    metadata:
      labels:
        app: my_web
    spec:
      containers:
        - image: my_web:latest
          name: my_web
          ports:
            - containerPort: 8080

解答

Ingress 本身不直接对外暴露端口,它的流量入口完全依赖对应的 Ingress Controller(这里是nginx-ingress-controller)的服务暴露方式。

你的问题根源在于:

  • 你把test.foo.com映射到了127.0.0.1,但如果nginx-ingress-controller的服务没有把80端口暴露到本地,直接访问127.0.0.1:80肯定连不上。
  • 你能访问localhost:8080是直接走了my_web服务的LoadBalancer端口,和Ingress的流量通道完全无关。

要解决这个问题,你需要:

  1. 查看nginx-ingress-controller的服务状态:
    kubectl get svc -n ingress-nginx  # 若你的Ingress Controller不在这个命名空间,替换成实际命名空间
    
    看这个服务的TYPE是LoadBalancer还是NodePort,以及对应的端口映射(比如80端口对应的外部IP或NodePort)。
  2. 调整访问方式:
    • 如果是LoadBalancer类型,把test.foo.com映射到该服务的EXTERNAL-IP后再访问;
    • 如果是NodePort类型,访问时要加上对应的NodePort,比如 curl http://test.foo.com:<NodePort>。
  3. 额外注意:你的Ingress配置里没配置TLS,但预期路径提到了SSL,不过当前先解决80端口的连通问题即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 07:22:54