From 31a056e549077a44e458dd6e338c9c64627d818f Mon Sep 17 00:00:00 2001 From: Bettygogo2021 <91529409+Bettygogo2021@users.noreply.github.com> Date: Fri, 12 Aug 2022 21:13:08 +0800 Subject: [PATCH] update byop Signed-off-by: Bettygogo2021 <91529409+Bettygogo2021@users.noreply.github.com> --- .../zh/docs/v3.3/faq/observability/byop.md | 109 ++++++++++-------- 1 file changed, 60 insertions(+), 49 deletions(-) diff --git a/content/zh/docs/v3.3/faq/observability/byop.md b/content/zh/docs/v3.3/faq/observability/byop.md index 2d6e7c59e..77fa7791f 100644 --- a/content/zh/docs/v3.3/faq/observability/byop.md +++ b/content/zh/docs/v3.3/faq/observability/byop.md @@ -46,7 +46,7 @@ KubeSphere 3.3.0 已经过认证,可以与以下 Prometheus 堆栈组件搭配 - Prometheus Operator **v0.55.1+** - Prometheus **v2.34.0+** - Alertmanager **v0.23.0+** -- kube-state-metrics **v2.3.0** +- kube-state-metrics **v2.5.0** - node-exporter **v1.3.1** 请确保您的 Prometheus 堆栈组件版本符合上述版本要求,尤其是 **node-exporter** 和 **kube-state-metrics**。 @@ -57,92 +57,97 @@ KubeSphere 3.3.0 已经过认证,可以与以下 Prometheus 堆栈组件搭配 {{}} -Prometheus 堆栈可以通过多种方式进行安装。下面的步骤演示如何使用**上游 `kube-prometheus`** 将 Prometheus 堆栈安装至命名空间 `monitoring` 中。 +Prometheus 堆栈可以通过多种方式进行安装。下面的步骤演示如何使用 `ks-prometheus`(基于上游的 `kube-prometheus` 项目) 将 Prometheus 堆栈安装至命名空间 `monitoring` 中。 -1. 获取 v0.6.0 版 kube-prometheus,它的 node-exporter 版本为 v1.3.1,与 KubeSphere 3.3.0 所使用的版本相匹配。 +1. 获取 KubeSphere 3.3.0 所使用的 `ks-prometheus`。 ```bash - cd ~ && git clone https://github.com/prometheus-operator/kube-prometheus.git && cd kube-prometheus && git checkout tags/v0.6.0 -b v0.6.0 + cd ~ && git clone -b release-3.3 https://github.com/kubesphere/ks-prometheus.git && cd ks-prometheus ``` -2. 设置命名空间 `monitoring`,安装 Prometheus Operator 和相应角色: +2. 设置命名空间。 ```bash - kubectl apply -f manifests/setup/ + sed -i 's/kubesphere-monitoring-system/monitoring/g' kustomization.yaml ``` -3. 稍等片刻待 Prometheus Operator 启动并运行。 +3. (可选)移除不必要的组件。例如,KubeSphere 未启用 Grafana 时,可以删除 `kustomization.yaml` 中的 `grafana` 部分: ```bash - kubectl -n monitoring get pod --watch + sed -i '/manifests\/grafana\//d' kustomization.yaml ``` -4. 移除不必要组件,例如 Prometheus Adapter。 +4. 安装堆栈。 ```bash - rm -rf manifests/prometheus-adapter-*.yaml - ``` - -5. 将 kube-state-metrics 的版本变更为 KubeSphere 3.3.0 所使用的 v2.3.0。 - - ```bash - sed -i 's/v1.9.5/v1.9.6/g' manifests/kube-state-metrics-deployment.yaml - ``` - -6. 安装 Prometheus、Alertmanager、Grafana、kube-state-metrics 以及 node-exporter。您可以只应用 YAML 文件 `kube-state-metrics-*.yaml` 或 `node-exporter-*.yaml` 来分别安装 kube-state-metrics 或 node-exporter。 - - ```bash - kubectl apply -f manifests/ + kubectl apply -k . ``` ### 步骤 3:将 KubeSphere 自定义组件安装至您的 Prometheus 堆栈 {{< notice note >}} -KubeSphere 3.3.0 使用 Prometheus Operator 来管理 Prometheus/Alertmanager 配置和生命周期、ServiceMonitor(用于管理抓取配置)和 PrometheusRule(用于管理 Prometheus 记录/告警规则)。 +如果您的 Prometheus 堆栈是通过 `ks-prometheus` 进行安装,您可以跳过此步骤。 -[KubeSphere kustomization](https://github.com/kubesphere/kube-prometheus/blob/ks-v3.0/kustomize/kustomization.yaml) 中列出了一些条目,其中 `prometheus-rules.yaml` 和 `prometheus-rulesEtcd.yaml` 是 KubeSphere 3.3.0 正常运行的必要条件,其他均为可选。如果您不希望现有 Alertmanager 的配置被覆盖,您可以移除 `alertmanager-secret.yaml`。如果您不希望自己的 ServiceMonitor 被覆盖(KubeSphere 自定义的 ServiceMonitor 弃用许多无关指标,以便 Prometheus 只存储最有用的指标),您可以移除 `xxx-serviceMonitor.yaml`。 +KubeSphere 3.3.0 使用 Prometheus Operator 来管理 Prometheus/Alertmanager 配置和生命周期、ServiceMonitor(用于管理抓取配置)和 PrometheusRule(用于管理 Prometheus 记录/告警规则)。 如果您的 Prometheus 堆栈不是由 Prometheus Operator 进行管理,您可以跳过此步骤。但请务必确保: -- 您必须将 [PrometheusRule](https://github.com/kubesphere/kube-prometheus/blob/ks-v3.0/kustomize/prometheus-rules.yaml) 和 [PrometheusRule for etcd](https://github.com/kubesphere/kube-prometheus/blob/ks-v3.0/kustomize/prometheus-rulesEtcd.yaml) 中的记录/告警规则复制至您的 Prometheus 配置中,以便 KubeSphere 3.3.0 能够正常运行。 +- 您必须将 [PrometheusRule](https://github.com/kubesphere/ks-prometheus/blob/release-3.3/manifests/kubernetes/kubernetes-prometheusRule.yaml) 和 [PrometheusRule for etcd](https://github.com/kubesphere/ks-prometheus/blob/release-3.3/manifests/etcd/prometheus-rulesEtcd.yaml) 中的记录/告警规则复制至您的 Prometheus 配置中,以便 KubeSphere 3.3.0 能够正常运行。 -- 配置您的 Prometheus,使其抓取指标的目标 (Target) 与 [KubeSphere kustomization](https://github.com/kubesphere/kube-prometheus/blob/ks-v3.0/kustomize/kustomization.yaml) 中列出的 ServiceMonitor 的目标相同。 +- 配置您的 Prometheus,使其抓取指标的目标 (Target) 与 各组件的 [serviceMonitor](https://github.com/kubesphere/ks-prometheus/tree/release-3.3/manifests) 文件中列出的目标相同。 {{}} -1. 获取 KubeSphere 3.3.0 的自定义 kube-prometheus。 +1. 获取 KubeSphere 3.3.0 所使用的 `ks-prometheus`。 ```bash - cd ~ && mkdir kubesphere && cd kubesphere && git clone https://github.com/kubesphere/kube-prometheus.git && cd kube-prometheus/kustomize + cd ~ && git clone -b release-3.3 https://github.com/kubesphere/ks-prometheus.git && cd ks-prometheus ``` -2. 将命名空间更改为您自己部署 Prometheus 堆栈的命名空间。例如,如果您按照步骤 2 将 Prometheus 安装在命名空间 `monitoring` 中,这里即为 `monitoring`。 +2. 设置 `kustomization.yaml`,仅保留如下内容。 - ```bash - sed -i 's/my-namespace//g' kustomization.yaml + ```yaml + apiVersion: kustomize.config.k8s.io/v1beta1 + kind: Kustomization + namespace: + resources: + - ./manifests/alertmanager/alertmanager-secret.yaml + - ./manifests/etcd/prometheus-rulesEtcd.yaml + - ./manifests/kube-state-metrics/kube-state-metrics-serviceMonitor.yaml + - ./manifests/kubernetes/kubernetes-prometheusRule.yaml + - ./manifests/kubernetes/kubernetes-serviceKubeControllerManager.yaml + - ./manifests/kubernetes/kubernetes-serviceKubeScheduler.yaml + - ./manifests/kubernetes/kubernetes-serviceMonitorApiserver.yaml + - ./manifests/kubernetes/kubernetes-serviceMonitorCoreDNS.yaml + - ./manifests/kubernetes/kubernetes-serviceMonitorKubeControllerManager.yaml + - ./manifests/kubernetes/kubernetes-serviceMonitorKubeScheduler.yaml + - ./manifests/kubernetes/kubernetes-serviceMonitorKubelet.yaml + - ./manifests/node-exporter/node-exporter-serviceMonitor.yaml + - ./manifests/prometheus/prometheus-clusterRole.yaml ``` -3. 应用 KubeSphere 自定义组件,包括 Prometheus 规则、Alertmanager 配置和各种 ServiceMonitor 等。 + {{< notice note >}} + + - 将此处 `namespace` 的值设置为您自己的命名空间。例如,如果您在步骤 2 将 Prometheus 安装在命名空间 `monitoring` 中,这里即为 `monitoring`。 + - 如果您启用了 KubeSphere 的告警,还需要保留 `kustomization.yaml` 中的 `thanos-ruler` 部分。 + + {{}} + + +3. 安装以上 KubeSphere 必要组件。 ```bash kubectl apply -k . ``` -4. 配置服务 (Service) 用于暴露 kube-scheduler 和 kube-controller-manager 指标。 - - ```bash - kubectl apply -f ./prometheus-serviceKubeScheduler.yaml - kubectl apply -f ./prometheus-serviceKubeControllerManager.yaml - ``` - -5. 在您自己的命名空间中查找 Prometheus CR,通常为 Kubernetes。 +4. 在您自己的命名空间中查找 Prometheus CR,通常为 k8s。 ```bash kubectl -n get prometheus ``` -6. 将 Prometheus 规则评估间隔设置为 1m,与 KubeSphere 3.3.0 的自定义 ServiceMonitor 保持一致。规则评估间隔应大于或等于抓取间隔。 +5. 将 Prometheus 规则评估间隔设置为 1m,与 KubeSphere 3.3.0 的自定义 ServiceMonitor 保持一致。规则评估间隔应大于或等于抓取间隔。 ```bash kubectl -n patch prometheus k8s --patch '{ @@ -156,30 +161,36 @@ KubeSphere 3.3.0 使用 Prometheus Operator 来管理 Prometheus/Alertmanager 您自己的 Prometheus 堆栈现在已启动并运行,您可以更改 KubeSphere 的监控 Endpoint 来使用您自己的 Prometheus。 -1. 运行以下命令,编辑 `kubesphere-config`: +1. 运行以下命令,编辑 `kubesphere-config`。 ```bash kubectl edit cm -n kubesphere-system kubesphere-config ``` -2. 搜寻到 `monitoring endpoint` 部分,如下所示: +2. 搜索 `monitoring endpoint` 部分,如下所示。 - ```bash + ```yaml monitoring: endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090 ``` -3. 将 `monitoring endpoint` 更改为您自己的 Prometheus: +3. 将 `endpoint` 的值更改为您自己的 Prometheus。 - ```bash + ```yaml monitoring: endpoint: http://prometheus-operated.monitoring.svc:9090 ``` -4. 运行以下命令,重启 KubeSphere APIserver。 +4. 如果您启用了 KubeSphere 的告警组件,请搜索 `alerting` 的 `prometheusEndpoint` 和 `thanosRulerEndpoint`,并参照如下示例修改。KubeSphere Apiserver 将自动重启使设置生效。 - ```bash - kubectl -n kubesphere-system rollout restart deployment/ks-apiserver + ```yaml + ... + alerting: + ... + prometheusEndpoint: http://prometheus-operated.monitoring.svc:9090 + thanosRulerEndpoint: http://thanos-ruler-operated.monitoring.svc:10902 + ... + ... ``` {{< notice warning >}}