Appearance
kube-state-metricsでKubernetesリソースを監視
kube-state-metricsを用いて、Pod数やServiceの状態などKubernetes上のリソース状態を監視します。
インストール
cf. https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics
- helmでkube-state-metricsをインストールします:
shell
helm repo add helm-charts https://prometheus-community.github.io/helm-charts
helm install kube-state-metrics helm-charts/kube-state-metrics- Serviceが起動していることを確認します:
shell
kubectl get service -l app.kubernetes.io/name=kube-state-metrics- 外部から疎通が取れるようにtypeを
NodePortに変更します:
shell
kubectl patch service kube-state-metrics -p '{"spec": {"type": "NodePort", "ports": [{"nodePort": 30800, "port": 8080, "protocol": "TCP", "targetPort": 8080}]}}'- メトリクスが作成されていることを確認します:
shell
curl {Kubernetes cluster IP}:30800/metrics参照できるメトリクス一覧については公式ドキュメントを参照ください。
Grafanaなどでメトリクスを可視化したい場合は、まずPrometheusにデータをpullしてもらう必要があります。prometheus.ymlを書いてPrometheusを起動してください。