# Helm 安装 Kubernetes 监控套件

### 快速安装(无持久化) <a href="#e5-bf-ab-e9-80-9f-e5-ae-89-e8-a3-85-e6-97-a0-e6-8c-81-e4-b9-85-e5-8c-96" id="e5-bf-ab-e9-80-9f-e5-ae-89-e8-a3-85-e6-97-a0-e6-8c-81-e4-b9-85-e5-8c-96"></a>

```bash
[root@master ~]# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
[root@master ~]# helm repo update
[root@master ~]# helm search  repo  kube-prometheus-stack 
NAME                                            CHART VERSION   APP VERSION     DESCRIPTION                                       
prometheus-community/kube-prometheus-stack      57.0.3          v0.72.0         kube-prometheus-stack collects Kubernetes manif...

[root@master ~]# helm install op prometheus-community/kube-prometheus-stack --namespace kube-monitor --create-namespace
NAME: op
LAST DEPLOYED: Wed Mar 20 16:52:30 2024
NAMESPACE: kube-monitor
STATUS: deployed
REVISION: 1
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
  kubectl --namespace kube-monitor get pods -l "release=op"

Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.
```

* 查看版本： helm search repo prometheus-community/kube-prometheus-stack --versions
* 安裝指定版本： helm install my-prometheus prometheus-community/kube-prometheus-stack --version \<version\_number>

<figure><img src="/files/yWwf1IoIlCgTT8tgDzHJ" alt=""><figcaption></figcaption></figure>

**- 获取密码**

```bash
[root@master ~]# kubectl get secret op-grafana -n kube-monitor -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
prom-operator
```

### NodPort 方式暴露 <a href="#nodport-e6-96-b9-e5-bc-8f-e6-9a-b4-e9-9c-b2" id="nodport-e6-96-b9-e5-bc-8f-e6-9a-b4-e9-9c-b2"></a>

```bash
# Gafana 暴露
[root@master ~]# kubectl edit svc op-grafana -n kube-monitor
service/op-grafana edited
[root@master ~]# kubectl get svc op-grafana -n kube-monitor -o yaml |grep -i nodeport
    nodePort: 30300     # 自定义暴露端口,默认随机
  type: NodePort        # 类型模式

# Prometheus 暴露
[root@master ~]# kubectl edit svc op-kube-prometheus-stack-prometheus -n kube-monitor
service/op-kube-prometheus-stack-prometheus edited
[root@master ~]# kubectl get svc op-kube-prometheus-stack-prometheus -n kube-monitor -o yaml |grep -i nodeport
    nodePort: 30301
    nodePort: 31177
  type: NodePort
```

<figure><img src="/files/fZLJuFrTNFfkMvwTfsaf" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/cg33VpgzAxbtGbO3IdLY" alt=""><figcaption></figcaption></figure>

### Ingress-nginx 方式 <a href="#ingress-nginx-e6-96-b9-e5-bc-8f" id="ingress-nginx-e6-96-b9-e5-bc-8f"></a>

* 略

### **使用local pv持久化存储数据** <a href="#e4-bd-bf-e7-94-a8local-pv-e6-8c-81-e4-b9-85-e5-8c-96-e5-a-d-98-e5-82-a8-e6-95-b0-e6-8d-ae" id="e4-bd-bf-e7-94-a8local-pv-e6-8c-81-e4-b9-85-e5-8c-96-e5-a-d-98-e5-82-a8-e6-95-b0-e6-8d-ae"></a>

参考: Helm 安装prometheus-stack 使用local pv持久化存储数据-CSDN博客

### 多节点存储持久化 <a href="#e5-a4-9a-e8-8a-82-e7-82-b9-e5-a-d-98-e5-82-a8-e6-8c-81-e4-b9-85-e5-8c-96" id="e5-a4-9a-e8-8a-82-e7-82-b9-e5-a-d-98-e5-82-a8-e6-8c-81-e4-b9-85-e5-8c-96"></a>

* 去除节点亲和性即可

其他方式

* influxdb存储prometheus数据
* mysql存储grafana数据


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/kubernetes/helm/helm-an-zhuang-kubernetes-jian-kong-tao-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
