Skip to content

Instantly share code, notes, and snippets.

@tanan
Last active March 14, 2018 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanan/8b1ac5e7428ee0ed8fb8dc57a7947a46 to your computer and use it in GitHub Desktop.
Save tanan/8b1ac5e7428ee0ed8fb8dc57a7947a46 to your computer and use it in GitHub Desktop.

概要

kubernetesのmetricsをPrometheusを利用して収集する

  • 事前準備
  • クラスター構築
  • RBAC設定
  • コンテナ起動
  • namespace設定
  • configmap設定
    • Prometheus
    • external-url
  • deployment設定
    • Prometheus
  • service設定
    • Prometheus
  • node-exporter起動

1. 事前準備

  • GCPのプロジェクトを作成する
  • gcloudコマンドが使えるようにしておく
  • gcloud auth loginしておく

2. クラスター構築

  • クラスター作成
$ gcloud container clusters create sample-cluster

3. namespace作成

  • monitoring用namespace作成
$ kubectl apply -f https://github.com/tanan/gke-setting/raw/master/prometheus/yaml/namespace.yaml

4. RBAC設定

  • 自身のserviceaccountに権限付与
$ gcloud info | grep Account
$ kubectl create clusterrolebinding sample-cluster-admin-binding \
  --clusterrole=cluster-admin \
  --user=<gcloud infoで取得したアカウント情報>
  • serviceaccount作成
$ kubectl create serviceaccount prometheus --namespace monitoring
  • clusterRole作成 / Binding
$ kubectl apply -f https://github.com/tanan/gke-setting/raw/master/prometheus/yaml/role.yaml
$ kubectl create clusterrolebinding prometheus --clusterrole=all-reader --serviceaccount=monitoring:prometheus

5. コンテナ起動

  • configmap設定
$ kubectl -n monitoring apply -f https://github.com/tanan/gke-setting/raw/master/prometheus/yaml/prometheus-configmap.yaml
$ kubectl -n monitoring apply -f https://github.com/tanan/gke-setting/raw/master/prometheus/yaml/external-url-configmap.yaml
  • deployment設定
$ kubectl -n monitoring apply -f https://github.com/tanan/gke-setting/raw/master/prometheus/yaml/prometheus-deployment.yaml
  • service設定
$ kubectl -n monitoring apply -f https://github.com/tanan/gke-setting/raw/master/prometheus/yaml/prometheus-service.yaml

6. firewall設定

  • prometheusポート解放 VPCネットワーク > ファイアウォールルール > 新規作成
    • 名前: allow-default-prometheus
    • ネットワーク:default
    • ターゲット:ネットワーク上のすべてのインスタンス
    • ソースフィルタ(IP範囲): <your client ip> /32
    • プロトコルとポート: tcp:9090

7. 動作確認

  • Prometheusが稼働しているノードのGlobalIPを取得する
  • http://<globalip>:30001 へアクセス
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment