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

K3S集群中Nginx可通过Pod IP访问但无法通过域名访问故障解决

K3S环境Ingress域名访问异常解决记录

基础环境信息

  • 负载均衡器、Ingress Controller运行状态正常
  • 已部署Nginx Deployment及对应Service,服务暴露端口为80

异常现象

  1. Pod IP访问正常:
    执行curl 10.52.2.38可获得正常返回,命令行、浏览器访问10.52.2.38、10.52.2.39无论是否指定80端口均可正常访问
  2. 域名访问失败:

#curl mywebsite.com
curl: (7) Failed to connect to mywebsite.com port 80: No route to host

  1. localhost/127.0.0.1也无法正常访问服务,仅Pod IP访问生效

已尝试无效操作

  • 清空iptables规则
  • 禁用ufw防火墙
  • 在/etc/hosts中配置域名与负载均衡IP的映射规则

Ingress资源初始配置检查

执行kubectl describe ing minimal-ingress结果如下:

#kubectl describe ing minimal-ingress
Name:             minimal-ingress
Namespace:        default
Address:
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host             Path  Backends
  ----             ----  --------
  mywebsite.com 
                   /   nginx-deployment:80 (10.52.2.38:80,10.52.2.39:80)
Annotations:       nginx.ingress.kubernetes.io/rewrite-target: /
Events:            <none>

解决方案

Ingress资源未指定对应Ingress Class,导致Ingress Controller未识别加载该路由规则,需要在Ingress资源的spec字段中添加ingressClassName: nginx配置,参考配置如下:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  namespace: ingress
spec:
  ingressClassName: nginx

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 12:48:00