Kubernetes : Prometheus でモニタリングする2025/11/07 |
|
Prometheus をインストールして、Kubernetes クラスターの各種メトリクスをモニタリングできるようにします。 当例では以下のように 4 台のノードを使用して Kubernetes クラスターを構成しています。
+----------------------+ +----------------------+
| [ ctrl.srv.world ] | | [ dlp.srv.world ] |
| Manager Node | | Control Plane |
+-----------+----------+ +-----------+----------+
eth0|10.0.0.25 eth0|10.0.0.30
| |
------------+--------------------------+-----------
| |
eth0|10.0.0.51 eth0|10.0.0.52
+-----------+----------+ +-----------+----------+
| [ node01.srv.world ] | | [ node02.srv.world ] |
| Worker Node#1 | | Worker Node#2 |
+----------------------+ +----------------------+
|
| [1] |
Prometheus が使用する外部ストレージが必要となります。 |
| [2] | Helm で Prometheus チャートをインストールします。 |
|
suse@ctrl:~> helm repo add prometheus-community https://prometheus-community.github.io/helm-charts "prometheus-community" has been added to your repositories suse@ctrl:~> helm inspect values prometheus-community/kube-prometheus-stack > prometheus.yaml
suse@ctrl:~>
vi prometheus.yaml
# 1021-1028行目 : コメント解除して [storageClass] 変更
storage:
volumeClaimTemplate:
spec:
storageClassName: nfs-client
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
# selector: {}
# 1356-1364行目 : コメント解除して [storageClass] 変更
persistence:
enabled: true
type: sts
storageClassName: "nfs-client"
accessModes:
- ReadWriteOnce
size: 10Gi
finalizers:
- kubernetes.io/pvc-protection
# 4310-4319行目 : コメント解除して [storageClass] 変更
storageSpec:
## Using PersistentVolumeClaim
##
volumeClaimTemplate:
spec:
storageClassName: nfs-client
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
# selector: {}
# 5150-5157行目 : コメント解除して [storageClass] 変更
storage:
volumeClaimTemplate:
spec:
storageClassName: nfs-client
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
# selector: {}
# Prometheus 用のネームスペース作成 suse@ctrl:~> kubectl create namespace monitoring namespace/monitoring created helm install prometheus --namespace monitoring -f prometheus.yaml prometheus-community/kube-prometheus-stack
NAME: prometheus
LAST DEPLOYED: Fri Nov 7 12:30:01 2025
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
kubectl --namespace monitoring get pods -l "release=prometheus"
Get Grafana 'admin' user password by running:
kubectl --namespace monitoring get secrets prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 -d ; echo
Access Grafana local instance:
export POD_NAME=$(kubectl --namespace monitoring get pod -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=prometheus" -oname)
kubectl --namespace monitoring port-forward $POD_NAME 3000
Get your grafana admin user password by running:
kubectl get secret --namespace monitoring -l app.kubernetes.io/component=admin-secret -o jsonpath="{.items[0].data.admin-password}" | base64 --decode ; echo
Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.
suse@ctrl:~> kubectl get pods -n monitoring NAME READY STATUS RESTARTS AGE alertmanager-prometheus-kube-prometheus-alertmanager-0 2/2 Running 0 52s prometheus-grafana-85d6dd97b7-v4jqf 3/3 Running 0 52s prometheus-kube-prometheus-operator-5d49d65c67-5bpg6 1/1 Running 0 52s prometheus-kube-state-metrics-7bbd865dd5-w54nm 1/1 Running 0 52s prometheus-prometheus-kube-prometheus-prometheus-0 2/2 Running 0 52s prometheus-prometheus-node-exporter-89772 1/1 Running 0 52s prometheus-prometheus-node-exporter-bkvrj 1/1 Running 0 52s prometheus-prometheus-node-exporter-p4nnn 1/1 Running 0 52s # Grafana の admin パスワード確認 suse@ctrl:~> kubectl get secret --namespace monitoring -l app.kubernetes.io/component=admin-secret -o jsonpath="{.items[0].data.admin-password}" | base64 --decode ; echo lhyTEWJd5ceXUISUSVB9RSQqdnw9loG0QiHPFjXD # クラスター外からアクセスする場合はポートフォワード suse@ctrl:~> kubectl port-forward -n monitoring service/prometheus-kube-prometheus-prometheus --address 0.0.0.0 9090:9090 & suse@ctrl:~> kubectl port-forward -n monitoring service/prometheus-grafana --address 0.0.0.0 3000:80 &
|
| [3] |
Prometheus をポートフォワーディングした場合は、ローカルネットワーク内の任意のコンピューターで Web ブラウザーを起動して、以下の URL にアクセスします。 ⇒ http://(Manager ノードのホスト名 または IP アドレス):(設定したポート)/ 以下のように Prometheus UI が表示されれば OK です。 |
|
|
| [4] |
Grafana をポートフォワーディングした場合は、ローカルネットワーク内の任意のコンピューターで Web ブラウザーを起動して、以下の URL にアクセスします。 ⇒ http://(Manager ノードのホスト名 または IP アドレス):(設定したポート)/ 以下のように Grafana が表示されれば OK です。 |
|
|
|
|
|
|
| Sponsored Link |
|
|