使用helm离线安装prometheus和grafana

发布于:2025-06-22 ⋅ 阅读:(18) ⋅ 点赞:(0)

在线安装方式,由于网络限制,没有成功

安装方式链接:

prometheus 27.20.1 · prometheus/prometheus-community

安装prometheus

1、下载 Prometheus 压缩包
在 releases 中,找到自己想安装的版本:https://github.com/prometheus-community/helm-charts/releases/

wget https://github.com/prometheus-community/helm-charts/releases/download/prometheus-27.13.0/prometheus-27.13.0.tgz

配置 Prometheus 命名空间

kubectl get namespace monitoring || kubectl create namespace monitoring

配置持久化卷
创建 prometheus-pv.yaml 文件

apiVersion: v1
kind: PersistentVolume
metadata:
  name: prometheus-pv
spec:
  capacity:
    storage: 50Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs-client
  hostPath:
    path: /nfs/prometheus


创建 prometheus-pvc.yaml 文件

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prometheus-pvc
  namespace: monitoring
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
  storageClassName: nfs-client


执行安装 pv、pvc

kubectl apply -f prometheus-pv.yaml
kubectl apply -f prometheus-pvc.yaml


验证安装

kubectl get pv -n monitoring
kubectl get pvc -n monitoring


配置 Prometheus 自定义配置
创建 prometheus-custom-values.yaml 文件

server:
  persistentVolume:
    enabled: true
    size: 1024Gi
    storageClass: nfs-client
    existingClaim: prometheus-pvc
    
  securityContext:
    runAsUser: 65534  # Matches the 'nobody' user, commonly used by Prometheus
    runAsGroup: 65534
    fsGroup: 65534    # Ensures the mounted volume is writable by this group
 
alertmanager:
  persistentVolume:
    enabled: true
    size: 20Gi
    storageClass: "nfs-client"
    accessModes:
      - ReadWriteOnce
    annotations: {}

helm 离线安装

helm install prometheus ./prometheus-27.13.0.tgz --namespace monitoring -f prometheus-custom-values.yaml


安装完成,输出日志

NAME: prometheus
LAST DEPLOYED: Tue May 13 20:37:07 2025
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
prometheus-server.monitoring.svc.cluster.local
 
 
Get the Prometheus server URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace monitoring -l "app.kubernetes.io/name=prometheus,app.kubernetes.io/instance=prometheus" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace monitoring port-forward $POD_NAME 9090
 
 
The Prometheus alertmanager can be accessed via port 9093 on the following DNS name from within your cluster:
prometheus-alertmanager.monitoring.svc.cluster.local
 
 
Get the Alertmanager URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace monitoring -l "app.kubernetes.io/name=alertmanager,app.kubernetes.io/instance=prometheus" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace monitoring port-forward $POD_NAME 9093
#################################################################################
######   WARNING: Pod Security Policy has been disabled by default since    #####
######            it deprecated after k8s 1.25+. use                        #####
######            (index .Values "prometheus-node-exporter" "rbac"          #####
###### .          "pspEnabled") with (index .Values                         #####
######            "prometheus-node-exporter" "rbac" "pspAnnotations")       #####
######            in case you still need it.                                #####
#################################################################################
 
 
The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster:
prometheus-prometheus-pushgateway.monitoring.svc.cluster.local
 
 
Get the PushGateway URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus-pushgateway,component=pushgateway" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace monitoring port-forward $POD_NAME 9091
 
For more information on running Prometheus, visit:
https://prometheus.io/


卸载 Prometheus

helm uninstall prometheus --namespace monitoring

安装grafana

https://github.com/grafana/helm-charts/tags查找grafana的版本

下载grafana的helm-charts
https://github.com/grafana/helm-charts/archive/refs/tags/grafana-9.2.5.tar.gz

解压文件获得如下文件

执行安装命令:

helm install grafana ./grafana -n monitoring -f grafana/values.yaml

  执行结果输出

NAME: grafana
LAST DEPLOYED: Wed Jun 18 15:46:54 2025
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
NOTES:
1. Get your 'admin' user password by running:

   kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo


2. The Grafana server can be accessed via port 80 on the following DNS name from within your cluster:

   grafana.monitoring.svc.cluster.local

   Get the Grafana URL to visit by running these commands in the same shell:
     export POD_NAME=$(kubectl get pods --namespace monitoring -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
     kubectl --namespace monitoring port-forward $POD_NAME 3000

3. Login with the password from step 1 and the username: admin

              

参考链接:https://blog.csdn.net/Guzarish/article/details/148127389


网站公告

今日签到

点亮在社区的每一天
去签到