Grafana Kubernetes Monitoringを導入する

eBPF
k8s-monitoring

2025-05-08

#はじめに

Grafana Kubernetes Monitoringを導入することにしました。
背景として、Promtailを使っていましたが、非推奨になったため、Alloyに移行することになりました。
Grafana Kubernetes Monitoringは、AlloyとBeylaを使ったk8sの監視のためのHelm chartです。

#なぜAlloyに移行するのか

Caution

Promtail is now deprecated and will enter into Long-Term Support (LTS) beginning Feb. 13, 2025. This means that Promtail will no longer receive any new feature updates, but it will receive critical bug fixes and security fixes. Commercial support will end after the LTS phase, which we anticipate will extend for about 12 months until February 28, 2026. End-of-Life (EOL) phase for Promtail will begin once LTS ends. Promtail is expected to reach EOL on March 2, 2026, afterwards no future support or updates will be provided. All future feature development will occur in Grafana Alloy.

If you are currently using Promtail, you should plan your migration to Alloy. The Alloy migration documentation includes a migration tool for converting your Promtail configuration to an Alloy configuration with a single command.

出典: https://grafana.com/docs/loki/latest/send-data/promtail/

Promtailのページでは、上記のように非推奨の旨が書かれています。そして、Alloyに移行することが案内されています。

#Alloyとは

Grafana Alloy combines the strengths of the leading collectors into one place. Whether observing applications, infrastructure, or both, Grafana Alloy can collect, process, and export telemetry signals to scale and future-proof your observability approach.

出典: https://grafana.com/docs/alloy/latest/

日本語訳すると以下のようになります。

Grafana Alloyは、主要なコレクターの強みを1つに統合します。アプリケーション、インフラストラクチャ、またはその両方を監視する場合でも、Grafana Alloyはテレメトリ信号を収集、処理、エクスポートすることで、監視アプローチを拡張し、将来を見据えた運用を実現します。

すこし概念的な説明ですが、下記のMigrate from XXXでは、Prometheus(Metrics)、OptenTelemetry Collector(Trace)、Promtail(Log)などがあげられており、様々なデータを収集することができるようで、コレクターを統合するということのようです。

Migrate to Grafana Alloy | Grafana Alloy documentation
How to migrate to Grafana Alloy

  Migrate to Grafana Alloy |  Grafana Alloy documentation


 favicon grafana.com

  Migrate to Grafana Alloy |  Grafana Alloy documentation

下記のブログ記事では、GrafanaCON 2024でAlloyを発表したと書かれているので、比較的新しい製品です。

Introducing an OpenTelemetry Collector distribution with built-in Prometheus pipelines: Grafana Alloy | Grafana Labs
Grafana Alloy is a telemetry collector that is 100% OTLP compatible and offers native pipelines for OpenTelemetry and Prometheus telemetry formats, supporting metrics, logs, traces, and profiles.
Introducing an OpenTelemetry Collector distribution with built-in   Prometheus pipelines: Grafana Alloy | Grafana Labs favicon grafana.com
Introducing an OpenTelemetry Collector distribution with built-in   Prometheus pipelines: Grafana Alloy | Grafana Labs

#現状の構成

現状は、Promtailを使ってk8sのログを収集していました。
具体的には、loki-stackというHelm chartを使って、Loki+Promtailをk8sにデプロイしていました。

Alloy単体でもHelm chartが公開されているようですが、いろいろ調べていくと、Grafana Kubernetes MonitoringというHelm chartがあり、一からAlloyを構成するよりも、こちらを使った方が便利だと思ったので、こちらを使うことにしました。Grafana Kubernetes Monitoringは、Alloyの他に、Beylaも含まれており、eBPFを使った監視もできるようです。

#Grafana Kubernetes Monitoringとは

The Grafana Kubernetes Monitoring Helm chart offers a complete solution for configuring infrastructure, automatic instrumentation, and gathering telemetry. The benefits of using this chart include:

  • Flexible architecture
  • Compatibility with existing systems such as OpenTelemetry and Prometheus Operators
  • Scalability for all Cluster sizes
  • Built-in testing and schemas to help you avoid errors

出典: https://grafana.com/docs/grafana-cloud/monitor-infrastructure/kubernetes-monitoring/configuration/helm-chart-config/helm-chart/

kubernetesの監視のためのソリューション全部入りのような感じです。

以下のパッケージが含まれているようです。

  • Grafana Alloy
  • Grafana Beyla
  • Node Exporter
  • Windows Exporter
  • kube-state-metrics
  • OpenCost
  • Kepler

#使ってみた感想

#Pros

  • Helmで簡単にデプロイできる

    Helmで簡単にデプロイできるので、すぐに試すことができました。Helmの設定も、k8s-monitoring-helmのREADMEを参考にしながら、必要な部分だけを変更していくことで、すぐに動きました。

  • eBPFを使った監視ができる

    Profiling, Tracing、MetricsをeBPFで収集することができるようです。これによって、個別のアプリケーションにProfiler, Tracerの設定をする必要がなくなります。これがかなり便利です。

#Cons

  • Grafana Alloy、Beylaの設定が難しい

    これらは、今回初めて導入して慣れていないというのもありますが、設定が難しいと思いました。できることの範囲が広いので、とにかく設定がたくさんあります。自分がやりたいことを実現するためにどのように設定すればよいかが、調べてもすぐにはわからなかったです。k8s-monitoring-helmには、かんたんなExampleがあるので、これらをベースにして、設定をすればすぐに動きますが、後述のように細かな設定は、実際にAlloyの設定がどのようにConfigMapに反映されるのかを確認しながら、設定をする必要がありました。Beylaも同様です。これらを設定のリファレンスと見比べながら調整することになります。

  • デフォルトですべてを監視対象にすると、負荷が高い

    例えば、Auto instrumentationを有効にすると、すべてのNamespaceが対象になるので、負荷が高くなります。これを避けるためには、Namespaceを指定する必要があります。他にも、Healthzのエンドポイントは、トレースが不要だったので、特定のパスを無視する設定をする必要がありました。

#まとめ

今回は、Grafana Kubernetes Monitoringを導入してみました。
まだ導入して間もないので評価が難しいですが、eBPFがかなり便利なので、これだけでも導入した価値があると思います。