# 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="https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2FcD8nJLvMTBVVkeS4LqIX%2Fimage.png?alt=media&#x26;token=cbe9e2a4-9586-4a1b-8cd8-777e04ce238d" 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="https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2F4I4XBI5iWSjevoH9pT2j%2Fimage.png?alt=media&#x26;token=9c833b92-ad90-4cf2-b140-619317218fba" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2FZunUcbOXUlxSoxTcKphB%2Fimage.png?alt=media&#x26;token=9733187b-f911-43fd-b207-a2226788ce0c" 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数据
