Skip to content

Redis Exporter 部署

使用 prometheus-community Helm Chart 部署 Redis Exporter,將 Redis 執行時指標匯出至 Prometheus。

概述

Redis Exporter(oliver006/redis_exporter)連線至 Redis 伺服器,採集記憶體使用量、命中率、連線數、複寫延遲等指標,供 Prometheus 抓取。透過 prometheus-community 提供的 prometheus-redis-exporter Helm Chart 部署至 monitoring namespace。

Redis 密碼透過 values.yamlauth.redisPassword 傳入,目前以明文儲存,建議改用 Kubernetes Secret 管理(透過 auth.secret 欄位引用)。

核心內容

連線設定

Exporter 透過標準的 Redis URI 指定連線目標:

redis://<service-name>.<namespace>.svc.cluster.local:<port>

若 Redis 啟用了密碼認證,需在 auth 區塊設定。每個 Redis Exporter 實例只能監控一個 Redis 端點(Master 或特定 Replica),若需同時監控 Master 和 Replicas,需部署多個 Exporter 實例。

認證管理最佳實踐

方式設定安全性
明文密碼(目前)auth.redisPassword: "password"低(會存入 values)
Kubernetes Secret(推薦)auth.secret.name / auth.secret.key

關鍵要點

  • 每個 Exporter 實例對應一個 Redis 端點(Master 和 Replicas 需分別部署)
  • auth.enabled: trueredisPassword 不為空時才啟用認證
  • 明文密碼存於 values.yaml 是技術債,應改用 Secret 管理
  • --insecure-skip-tls-verify 用於非生產環境安裝

實際應用

Redis Exporter 部署後,在 Prometheusvalues.yaml 中已設定抓取 redis-exporter-prometheus-redis-exporter:9121。Prometheus 抓取指標後可在 Grafana 中使用官方提供的 Redis Dashboard 範本(Grafana Dashboard #763)快速建立監控視圖。

部署設定參考

以下為實際部署時使用的完整設定,供日後查詢與複製使用。

環境參數

項目
Release 名稱redis-exporter
Namespacemonitoring
Redis 連線位址redis://redis-k8s-master.redis-system.svc.cluster.local:6379
Redis Serviceredis-k8s-master
Redis Namespaceredis-system
Port6379
密碼Bed200@2022

安裝指令

bash
helm install redis-exporter \
  -f values-redis.yaml \
  --insecure-skip-tls-verify \
  --namespace monitoring \
  prometheus-community/prometheus-redis-exporter

values-redis.yaml

yaml
redisAddress: redis://redis-k8s-master.redis-system.svc.cluster.local:6379

auth:
  enabled: true
  # Redis password (when not stored in a secret)
  redisPassword: "Bed200@2022"

相關概念

來源