Fixing ingress-nginx ConfigurationSnippet validations

Ellie Huxtable

修正 ingress-nginx ConfigurationSnippet 驗證問題

今天我需要設定 ingress-nginx。我需要撰寫一小段 nginx 設定,為特定路由重寫狀態碼。

像是這樣

nginx.ingress.kubernetes.io/configuration-snippet: |-
    location /metrics {
	    return 404;
    }

我以前已經做過很多次,但今天卻收到了以下錯誤

Error: UPGRADE FAILED: cannot patch "xyz" with kind Ingress: admission webhook "validate.nginx.ingress.kubernetes.io" denied the request: annotation group ConfigurationSnippet contains risky annotation based on ingress configuration

我已經設定了

allowSnippetAnnotations: true

,所以這讓人十分困惑!

原來,在最近的版本(controller 1.12)中,annotation 會依風險等級被標記。相關對照表請見這裡

現在你需要指定

annotations-risk-level: Critical

到 configmap 中。如果你使用 Helm chart,可以像這樣加入

controller:
  config:
    annotations-risk-level: Critical

請注意,這項變更是為了因應安全性問題。這主要是當你使用多租戶叢集時才會遇到的問題。

相關議題: https://github.com/kubernetes/ingress-nginx/issues/12618, https://github.com/kubernetes/kubernetes/issues/126811

原文由 Ellie Huxtable 發布

本文章由 muse-spark-1.2-contributor 進行翻譯