LoginSignup
0
1

Helmを使ってPrometheus環境を構築したよ

Last updated at Posted at 2024-04-01

はじめに

prometheusを初めて扱ったので備忘録として記事を作成しました

Helm

  • helmとはKubernetes用のパッケージマネージャという理解でOK
  • アプリが簡単にデプロイできる点とカスタマイズできる点がめちゃ便利
  • values.yamlでアプリのパラメータを管理し、このファイルをマニフェストが参照してk8sオブジェクトが作成される
  • チャート=クラスでリリース=インスタンスみたいな理解でOK

Helmインストール

スクリプトを実行して最新のhelmをインストールする場合

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

kube-prometheus-stack

k8sへpromethuesのインストール手段は様々あるが、kube-prometheus-stackチャートを使用すると、デフォルトでalertmanager,grafana,exporterなど必要なコンポーネントも一括してデプロイしてくれるので便利。

kube-prometheus-stackインストール

1. レポジトリ追加
まずは使用するレポジトリprometheus-communityをローカルに追加します。

helm repo add prometheus-community https://prometheus- community.github.io/helm-charts
helm repo update

2. カスタマイズ
以下のコマンドでvalues.yamlを抽出し、カスタマイズする

helm show values prometheus-community/kube-prometheus-stack > values.yaml
vi values.yaml

3. インストール
名前空間を作成し、任意のリリース名で編集したvalues.yamlをもとにインストールする。

kubectl create ns monitoring
helm install [RELEASE_NAME] -f values.yaml prometheus-community/kube-prometheus-stack -n monitoring

4. インストール確認

kubectl get pod -n monitoring
alertmanager-kube-prometheus-stack-alertmanager-0           2/2     Running   0          30s
kube-prometheus-stack-grafana-*                             3/3     Running   0          30s
kube-prometheus-stack-kube-state-metrics-*                  1/1     Running   0          30s
kube-prometheus-stack-operator-*                            1/1     Running   0          30s
kube-prometheus-stack-prometheus-node-exporter-*            1/1     Running   0          30s
prometheus-kube-prometheus-stack-prometheus-0               2/2     Running   0          30s

備考

  • デフォルトではprometheusで収集したデータやgrafanaのダッシュボードなどはPODの再起動によって消えてしまうのでデータ永続化のために、Persistent Volumeを作成する必要がある
  • Prometheus公式にはストレージにNFSを使用することは非推奨となっているが、kube-prometheus-stackの前身であるprometheus-operatorにはNFSの使用例が記載されている。使っていいのか不安だったのでローカルストレージを使いました
  • 収集したメトリクスはデフォルトで10日後に削除されるので、必要に応じてvalues.yamlのprometheus.prometheusSpec.retentionを変更する
  • kube-prometheus-stackをアンインストールする場合、CRDや作成したPV、PVCは残ってしまうので手動で削除する必要がある
helm uninstall kube-prometheus-stack -n monitoring
kubectl delete crd alertmanagerconfigs.monitoring.coreos.com
kubectl delete crd alertmanagers.monitoring.coreos.com
kubectl delete crd podmonitors.monitoring.coreos.com
kubectl delete crd probes.monitoring.coreos.com
kubectl delete crd prometheusagents.monitoring.coreos.com
kubectl delete crd prometheuses.monitoring.coreos.com
kubectl delete crd prometheusrules.monitoring.coreos.com
kubectl delete crd scrapeconfigs.monitoring.coreos.com
kubectl delete crd servicemonitors.monitoring.coreos.com
kubectl delete crd thanosrulers.monitoring.coreos.com

終わりに

初めてprometheusを扱ったが、kube-stack-prometheusを使用することで簡単にリソース監視環境を構築することができた。改善できる点としては、デフォルトの設定だと必要ないメトリクスまで収集してしまいストレージを圧迫してしまうので、必要なもののみ収集する設定するができたらよかった。また独自のクエリ言語PromeQLに手こずった。PromeQLについての記事も今度書こうと思います。

不明点、間違っている点ありましたら、ご指摘ください🙏

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1