0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Go言語で学ぶWebアプリケーション開発7:[モニタリング & サービスメッシュ]

Posted at

はじめに

前回の記事では、AWS・GCP・Azureなどの大型クラウドへのデプロイ方法(ECS, GKE, AKS)とKubernetesの CI/CD パイプライン構築(GitHub Actions, ArgoCD, 自動テスト)について解説しました。
今回は、Kubernetesクラスタの運用をより高度にするためのモニタリング(Prometheus & Grafana)とサービスメッシュ(Istio) について解説します。

対象読者

  • Kubernetesクラスタのモニタリングを実施したい方
  • サービスメッシュ(Istio)を導入し、マイクロサービスの通信を管理したい方

目次

  1. Kubernetesのモニタリング(Prometheus & Grafana)
    • Prometheusの基本概念
    • Prometheusのインストールと設定
    • Grafanaを使った可視化
  2. クラウドネイティブなサービスメッシュ(Istio)
    • Istioの基本概念
    • Istioのインストールと設定
    • Istioを活用したトラフィック管理

1. Kubernetesのモニタリング(Prometheus & Grafana)

1.1 Prometheus の基本概念

Prometheusは、オープンソースのモニタリング&アラートツールであり、Kubernetesのパフォーマンス監視に最適 です。

Prometheus の特徴:

  • 時系列データを収集 & 保存(Kubernetesのメトリクスを監視)
  • **クエリ言語(PromQL)**を使用したデータ分析
  • **アラート通知(Alertmanager)**を設定可能

1.2 Prometheus のインストールと設定

まず、Helmを使用してKubernetesクラスタにPrometheusをインストールします。

ステップ 1: Helmのインストール

brew install helm

ステップ 2: Prometheusのインストール

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

ステップ 3: Prometheusのポートフォワーディング

kubectl port-forward -n default svc/prometheus-kube-prometheus-prometheus 9090:9090
  • http://localhost:9090 にアクセスするとPrometheusのUIが確認できます。

1.3 Grafanaを使った可視化

Grafana は、データを視覚化するためのツールで、Prometheusとの統合が容易です。

ステップ 1: Grafanaのインストール

helm install grafana prometheus-community/grafana

ステップ 2: Grafana に Prometheus をデータソースとして追加

  • http://localhost:3000 にアクセス
  • admin / admin でログイン
  • データソースを追加 → Prometheus の URL http://prometheus-kube-prometheus-prometheus.default.svc:9090 を設定
  • Kubernetesメトリクス用のダッシュボード(ID: 3119)をインポート

これでCPU 使用率、メモリ使用量、ネットワークトラフィックなどが視覚的に確認可能になります。


2. クラウドネイティブなサービスメッシュ(Istio)

2.1 Istio の基本概念

Istioは、Kubernetesクラスタ内のマイクロサービス間の通信を制御 & 管理するためのサービスメッシュツールです。

Istioの特徴:

  • トラフィック制御(ロードバランシング、カナリアリリース)
  • セキュリティ強化(mTLS による暗号化)
  • 観測性の向上(メトリクス & ログ収集)

2.2 Istio のインストールと設定

ステップ 1: Istio CLIのインストール

curl -L https://istio.io/downloadIstio | sh -
cd istio-*/
export PATH=$PWD/bin:$PATH

ステップ 2: Istioのインストール

istioctl install --set profile=demo -y
kubectl label namespace default istio-injection=enabled

ステップ 3: Istio Gatewayの設定

istio-gateway.yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
kubectl apply -f istio-gateway.yaml

2.3 Istioを活用したトラフィック管理

カナリアリリース(新バージョンを徐々に適用)

カナリアルール(canary.yaml)

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-app
spec:
  hosts:
  - "my-app.example.com"
  http:
  - route:
    - destination:
        host: my-app
        subset: v1
      weight: 80
    - destination:
        host: my-app
        subset: v2
      weight: 20
kubectl apply -f canary.yaml

これで、トラフィックの80%をv1に、20%をv2にルーティングするカナリアリリースが可能になります。


まとめ

項目 説明
Prometheus Kubernetesクラスタのメトリクスを収集 & 監視するツール
Grafana モニタリングデータを可視化し、ダッシュボードを提供するツール
Istio マイクロサービス間の通信を管理し、セキュリティと可視性を向上させるサービスメッシュ
トラフィック管理 Istioを使ったカナリアリリースやルーティング制御

モニタリングやトラフィック管理を行えると、パフォーマンスとしてもセキュリティとしてもより強固なものにすることができます!
若干取っつきにくい概念もあるかも知れませんが、覚えるとさらなるレベルアップができると思います!
引き続きGoを学習していきたい!!!!!!!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?