kubernetes config_error ai_generated true

Error: rewrite-target annotation value must be a valid regex

ID: kubernetes/ingress-rewrite-target-missing

Also available as: JSON · Markdown · 中文
88%Fix Rate
82%Confidence
1Evidence
2023-08-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx-ingress-controller 1.8.0 active
nginx-ingress-controller 1.9.0 active
ingress-nginx 4.7.0 active

Root Cause

The nginx.ingress.kubernetes.io/rewrite-target annotation is set to an invalid regex pattern or empty string, causing the ingress controller to reject the configuration.

generic

中文

nginx.ingress.kubernetes.io/rewrite-target 注解被设置为无效的正则表达式模式或空字符串,导致 Ingress 控制器拒绝该配置。

Official Documentation

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite

Workarounds

  1. 90% success Use a valid regex with capture groups: 'nginx.ingress.kubernetes.io/rewrite-target: /$2' and path: '/api(/|$)(.*)'
    Use a valid regex with capture groups: 'nginx.ingress.kubernetes.io/rewrite-target: /$2' and path: '/api(/|$)(.*)'
  2. 85% success Validate regex with online tool before applying, then check with: kubectl describe ingress <ingress-name>
    Validate regex with online tool before applying, then check with: kubectl describe ingress <ingress-name>

中文步骤

  1. Use a valid regex with capture groups: 'nginx.ingress.kubernetes.io/rewrite-target: /$2' and path: '/api(/|$)(.*)'
  2. Validate regex with online tool before applying, then check with: kubectl describe ingress <ingress-name>

Dead Ends

Common approaches that don't work:

  1. Setting rewrite-target to '/' with no capture groups 70% fail

    路径不匹配时重写为根路径会导致 404,且不解决正则无效问题

  2. Removing the rewrite-target annotation entirely 60% fail

    后端服务可能依赖路径重写,移除会导致路由错误

  3. Using a wildcard '*' in the regex pattern 95% fail

    星号不是有效正则,反而会触发相同错误