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

Traefik忽略K8s中IngressRoute与Ingress资源返回404问题排查

问题现象
  • 基于Helm Chart部署Traefik后,手动创建的Dashboard IngressRoute、Basic Auth Middleware访问返回404
  • 集群内所有Ingress资源访问全部返回404,对接其他业务服务的IngressRoute也无法正常路由
  • 运行环境版本:
    • Traefik:2.7.1
    • Kubernetes:v1.22.8-gke.202(GKE Autopilot)
现有部署配置

Helm 自定义参数

additionalArguments:
  - "--log.level=DEBUG"
  - "--entrypoints.web.http.redirections.entryPoint.to=:443"
  - "--providers.file.filename=/config/dynamic.yaml"

volumes:
  - name: tls-cert
    mountPath: "/certs"
    type: secret
  - name: traefik-config
    mountPath: "/config"
    type: configMap

service:
  spec:
    externalTrafficPolicy: Local
    loadBalancerIP: "xxx.xxx.xxx.xxx"

ingressRoute:
  dashboard:
    enabled: false

动态配置ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: traefik-config
  namespace: ingress
data:
  dynamic.yaml: |
    tls:
      stores:
        default:
          defaultCertificate:
            certFile: '/certs/tls.crt'
            keyFile: '/certs/tls.key'

路由与鉴权资源配置

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: dashboard
  namespace: ingress
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`traefik.example.domain`)
      kind: Rule
      services:
        - name: api@internal
          kind: TraefikService
      middlewares:
        - name: admin-auth
          namespace: ingress
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: admin-auth
spec:
  basicAuth:
    namespace: ingress
    secret: ingress-authsecret
---
apiVersion: v1
kind: Secret
metadata:
  name: ingress-authsecret
  namespace: ingress
data:
  users: some-base64-encoded-credentials
问题根因与修复方案

1. HTTP转HTTPS重定向参数配置非法(核心故障点)

additionalArguments中配置的重定向规则不符合Traefik参数规范:--entrypoints.web.http.redirections.entryPoint.to要求填入目标entrypoint的名称,而非端口号。你填入的:443会导致Traefik启动时无法找到对应目标entrypoint,web entrypoint的重定向中间件加载失败,直接破坏整个entrypoint的路由表初始化逻辑,所有关联路由全部无法注册,最终访问返回404。

修复方式:替换原有错误重定向参数为标准配置:

additionalArguments:
  - "--log.level=DEBUG"
  # 指向默认HTTPS entrypoint名称websecure
  - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
  - "--entrypoints.web.http.redirections.entryPoint.scheme=https"
  - "--entrypoints.web.http.redirections.entryPoint.permanent=true"
  - "--providers.file.filename=/config/dynamic.yaml"

2. BasicAuth Middleware存在无效字段

Traefik Middleware CRD的spec.basicAuth层级不存在namespace配置项,你在Middleware配置中添加的该字段属于无效配置,会导致Middleware资源解析失败,鉴权逻辑不生效。注意:namespace参数仅在IngressRoute引用Middleware时需要指定,无需在Middleware自身的spec中声明。

修复方式:删除Middleware中的无效namespace字段:

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: admin-auth
  namespace: ingress
spec:
  basicAuth:
    secret: ingress-authsecret

3. HTTPS入口的IngressRoute未声明TLS配置

你创建的Dashboard IngressRoute绑定了websecure(HTTPS 443端口)入口,但spec中未声明tls配置,Traefik不会将该路由注册到HTTPS监听器的路由表中,HTTPS访问时无法匹配到对应规则,直接返回404。

修复方式:在IngressRoute spec中添加TLS配置,关联动态配置中定义的default TLS存储:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: dashboard
  namespace: ingress
spec:
  entryPoints:
    - websecure
  # 新增TLS配置
  tls:
    store: default
  routes:
    - match: Host(`traefik.example.domain`)
      kind: Rule
      services:
        - name: api@internal
          kind: TraefikService
      middlewares:
        - name: admin-auth
          namespace: ingress

4. GKE Autopilot环境额外排查项

如果完成上述配置修改后仍存在路由不生效问题,检查以下两点:

  • 确认Helm安装时rbac.enabled配置为true(该参数默认开启,手动关闭会导致Traefik ServiceAccount无权限list、watch集群内的Ingress、IngressRoute、Middleware等资源,所有动态路由无法加载)
  • 查看Traefik Pod运行日志,确认不存在forbidden、cannot list resource类的权限报错,或GKE安全策略拦截的相关日志。

验证步骤

  1. 应用所有配置变更,等待Traefik Pod滚动重启完成
  2. 查看Traefik启动日志,确认无配置解析失败、权限不足类报错
  3. 访问http://traefik.example.domain,验证是否正常跳转到HTTPS地址
  4. 输入BasicAuth账号密码,验证是否可以正常打开Traefik Dashboard
  5. 测试其他业务的Ingress、IngressRoute路由,确认全部恢复正常

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 17:21:34