ServiceMonitor 需要填充 3 个条件,请确保您的集群和配置满足这些条件:https ://github.com/kubernetes/ingress-nginx/blob/6299c39842c31ff1e17d72503003ca36e2976a9a/charts/ingress-nginx/templates/controller-servicemonitor.yaml #L1
您的集群应该支持:monitoring.coreos.com/v1 API 版本
如果您使用 API 条件不存在的旧图表版本,您将能够使用当前 values.yaml 部署 ServiceMonitor
helm template ingress-nginx/ingress-nginx --values values.yaml --version "3.15.2" | grep -i mon
# Source: ingress-nginx/templates/controller-servicemonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
另外,请注意:https ://helm.sh/docs/helm/helm_template/
Render chart templates locally and display the output.
Any values that would normally be looked up or retrieved in-cluster will be faked locally. Additionally, none of the server-side testing of chart validity (e.g. whether an API is supported) is done.
这意味着如果你在你的机器上运行命令行,它永远不会显示,ServiceMonitor
除非你有一个支持的本地 k8s 集群monitoring.coreos.com/v1
或者你也伪造它:) 如下
helm template ingress-nginx/ingress-nginx --values values.yaml --version "4.0.5" --api-versions "monitoring.coreos.com/v1" | grep -i mon
# Source: ingress-nginx/templates/controller-servicemonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor