kubernetes
config_error
ai_generated
true
Error: rewrite-target annotation value must be a valid regex
ID: kubernetes/ingress-rewrite-target-missing
88%Fix Rate
82%Confidence
1Evidence
2023-08-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 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/#rewriteWorkarounds
-
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(/|$)(.*)'
-
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>
中文步骤
Use a valid regex with capture groups: 'nginx.ingress.kubernetes.io/rewrite-target: /$2' and path: '/api(/|$)(.*)'
Validate regex with online tool before applying, then check with: kubectl describe ingress <ingress-name>
Dead Ends
Common approaches that don't work:
-
Setting rewrite-target to '/' with no capture groups
70% fail
路径不匹配时重写为根路径会导致 404,且不解决正则无效问题
-
Removing the rewrite-target annotation entirely
60% fail
后端服务可能依赖路径重写,移除会导致路由错误
-
Using a wildcard '*' in the regex pattern
95% fail
星号不是有效正则,反而会触发相同错误