kubernetes config_error ai_generated true

错误:rewrite-target 注解值必须是有效的正则表达式

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

ID: kubernetes/ingress-rewrite-target-missing

其他格式: JSON · Markdown 中文 · English
88%修复率
82%置信度
1证据数
2023-08-15首次发现

版本兼容性

版本状态引入弃用备注
nginx-ingress-controller 1.8.0 active
nginx-ingress-controller 1.9.0 active
ingress-nginx 4.7.0 active

根因分析

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

English

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

官方文档

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

解决方案

  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>

无效尝试

常见但无效的做法:

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

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

  2. Removing the rewrite-target annotation entirely 60% 失败

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

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

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