2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

k3s上にhelmを用いてprometheusを導入

Posted at

先日来、学習用のk3sクラスタを構築してますが、ここにhelmを用いてprometheusを入れてみました。
kube-prometheus-stackを使ってみます。このkube-prometheus-stackとprometheus operatorとの関係性がよく分かってないんですけど、、、、

1.ソフトウェア構成

※AWS上の4インスタンスに構築したk3sクラスタ構成
Debian GNU/Linux 11
k3s version v1.23.8+k3s1 (53f2d4e7)
go version go1.17.5
Longhorn v1.3.0

2.導入手順

prometheus-communityのレポジトリを追加します。

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

valuesファイルを取得します。

helm inspect values prometheus-community/kube-prometheus-stack > prometheus_values.yaml

valuesファイルをお好みに合わせて修正します(後述)。
valuesファイルを修正したら、名前空間を作成した後にhelm installをします。

kubectl create ns prometheus
helm install prometheus -f .\prometheus_values.yaml prometheus-community/kube-prometheus-stack -n prometheus

3.valuesファイルの変更点

今回、以下のように変えてみました。
まず、データ永続化のために以下三か所のコメントを外し、longhornを使用するようにしました。

prometheus_values.yaml(抜粋)
alertmanager:
  alertmanagerSpec:
    storage:
      volumeClaimTemplate:
        spec:
          storageClassName: longhorn
          accessModes: ["ReadWriteOnce"]
          resources:
            requests:
              storage: 1Gi
          #selector: {}

prometheus:
  prometheusSpec:
    ## Prometheus StorageSpec for persistent data
    ## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/storage.md
    ##
    storageSpec:
    ## Using PersistentVolumeClaim
    ##
       volumeClaimTemplate:
         spec:
           storageClassName: longhorn
           accessModes: ["ReadWriteOnce"]
           resources:
             requests:
               storage: 1Gi
         #selector: {}

thanosRuler:
  thanosRulerSpec:
    storage:
      volumeClaimTemplate:
        spec:
          storageClassName: longhorn
          accessModes: ["ReadWriteOnce"]
          resources:
            requests:
              storage: 1Gi
        #selector: {}

また、nodeSelectorを指定できるところはラベルを指定して、適切なノードで配置されるようにしました。たまたまノードにlonghorn-nodeというものを指定していたのでそれをそのまま使いましたが、本来はprometheus配置用に別のラベルを作っておいた方がいいのかもしれません。

  nodeSelector:
    longhorn-node: 'true'

また、抽出したvaluesファイルにgrafanaとkube-state-metrics用のnodeSelectorの項がありません。ありませんが、リンク先のissueによると「追記してあげたら問題なく動く」という事なので追記します。

grafana:
  #add nodeSelector
  nodeSelector:
    longhorn-node: 'true'

kube-state-metrics:
  #add nodeSelector
  nodeSelector:
    longhorn-node: 'true'

4.UIにアクセス

PrometheusのUIにアクセスしてみましょう。サービス prometheus-kube-prometheus-prometheusでUIが公開されているので、これをポートフォワーディングしてみます。Lensを使ってイージーにやっちゃいました。
スクリーンショット 2022-07-27 100523.png
さらにgrafanaのUIにもアクセスしてみましょう。サービスprometheus-grafanaをこれまたLensでイージーにポートフォワーディングするとログイン画面が出てきます。
スクリーンショット 2022-07-27 grafana.png
adminのパスワードは、prom-operatorです。実はvaluesファイルに書いてあったりします。

grafana:
  adminPassword: prom-operator

しかしLens、便利ですね。

5.まとめ

kube-prometheus-stackを使って、PrometheusとGrafanaなど一式をk3sに導入しました。その際、データ永続化のためにlonghornを利用するようにしました。また、Prometheusなどが稼働するノードをnodeSelectorで指定してみました。
UIアクセスはLensを使って簡単にやってみました。

しかし、まだまだPrometheusというかk3sで何のパラメーターを見ればよいのか分かってないです。勉強が足りませんね、という初心者らしい一言でこの記事を締めたいと思います。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?