使用 Kustomize 部署 kube-prometheus-stack 不起作用



我正在尝试部署kube-prometheus-stackhttps://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack通过定制。但是我从部署中得到:

unable to recognize ".": no matches for kind "Alertmanager" in version "monitoring.coreos.com/v1"
unable to recognize ".": no matches for kind "Prometheus" in version "monitoring.coreos.com/v1"
unable to recognize ".": no matches for kind "PrometheusRule" in version "monitoring.coreos.com/v1"
...(and so on)

完整输出:https://app.warp.dev/block/JJwOYMJZng9CyBdVlBaIIF

我尝试在rancher桌面部署本地,但在docker桌面我得到相同的。

我所做的:没有这个堆栈的定制文件,所以我采用清单:

helm template prometheus-community/kube-prometheus-stack > prometheus.yaml

在这不起作用后,我尝试直接在我的定制。使用:

helmCharts:
- name: kube-prometheus-stack 
repo: https://prometheus-community.github.io/helm-charts
version: 35.0.3
releaseName: prometheus

并开始自定义:

kubectl kustomize . --enable-helm | kubectl apply -f -

都有同样的问题。

如果使用helm:

helm install prometheus prometheus-community/kube-prometheus-stack

工作。

有趣的是,当我卸载它:

helm uninstall prometheus

,然后通过定制

再次部署它
kubectl apply -k .
这是有效的,但这不是我需要的解决方案。那么我做错了什么呢?

在尝试部署"使用"的对象之前,需要给kubernetes一些时间来创建crd。那些crd。

下次只需应用一次,等待10秒,再次应用。甚至多次,直到错误消失。

我在使用Helmfile时遇到了类似的问题。当crd与资源同时部署时(在同一个图表中,甚至作为Helmfile依赖项),Helmfile验证将失败:

Error: unable to build kubernetes objects from release manifest: [unable to recognize "": no matches for kind "Alertmanager" in version "monitoring.coreos.com/v1", unable to recognize "": no matches for kind "Prometheus" in version "monitoring.coreos.com/v1", unable to recognize "": no matches for kind "ServiceMonitor" in version "monitoring.coreos.com/v1"]

然而,Kubernetes代理完全能够同时处理crd/资源创建。使用Helmfile的解决方案是在第一次部署时禁用验证:

helmfile.yaml

releases:
- name: prometheus
disableValidation: true # Missing CRDs on first deploy
installed: true
values:
- values.yaml

这是迄今为止我发现的唯一的解决方案,我不是很熟悉Kustomize,但我想一定有一种方法可以跳过验证?

希望这对你有帮助

我通过在kustomization.yaml中设置helmCharts.includeCRDs: true来解决这个问题。

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: monitoring
helmCharts:
- name: kube-prometheus-stack
repo: https://prometheus-community.github.io/helm-charts
version: 45.28.1
includeCRDs: true
releaseName: kube-prometheus-stack
namespace: monitoring
valuesFile: values.yaml

最新更新