MicroK8s : Prometheus を有効にする2020/08/17 |
Prometheus アドオンを有効にして、Prometheus による MicroK8s クラスターの各種メトリクスの収集を行います。
|
[1] | プライマリーノードで、Prometheus アドオンを有効にします。 |
root@dlp:~# microk8s enable prometheus dashboard dns Enabling Prometheus namespace/monitoring created customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created ..... ..... role.rbac.authorization.k8s.io/kubernetes-dashboard created clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created deployment.apps/kubernetes-dashboard created service/dashboard-metrics-scraper created deployment.apps/dashboard-metrics-scraper created If RBAC is not enabled access the dashboard using the default token retrieved with: token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1) microk8s kubectl -n kube-system describe secret $token In an RBAC enabled setup (microk8s enable RBAC) you need to create a user with restricted permissions as shown in: https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md Addon dns is already enabled.root@dlp:~# microk8s kubectl get services -n monitoring NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE alertmanager-main ClusterIP 10.152.183.5 <none> 9093/TCP 51m alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 51m grafana ClusterIP 10.152.183.94 <none> 3000/TCP 51m kube-state-metrics ClusterIP None <none> 8443/TCP,9443/TCP 51m node-exporter ClusterIP None <none> 9100/TCP 51m prometheus-adapter ClusterIP 10.152.183.14 <none> 443/TCP 51m prometheus-k8s ClusterIP 10.152.183.251 <none> 9090/TCP 51m prometheus-operated ClusterIP None <none> 9090/TCP 50m prometheus-operator ClusterIP None <none> 8080/TCP 51mroot@dlp:~# microk8s kubectl get pods -n monitoring NAME READY STATUS RESTARTS AGE alertmanager-main-0 2/2 Running 0 51m grafana-fbb6785d5-k8sc6 1/1 Running 0 52m kube-state-metrics-dcc94d9f8-bnskk 3/3 Running 0 52m node-exporter-8lg8k 2/2 Running 0 52m prometheus-adapter-5949969998-ss56p 1/1 Running 0 52m prometheus-k8s-0 3/3 Running 1 51m prometheus-operator-5c7dcf954-xrsp7 1/1 Running 0 52m # 外部からもアクセスできるようにポートフォワードする # Prometheus UI root@dlp:~# microk8s kubectl port-forward -n monitoring service/prometheus-k8s --address 0.0.0.0 9090:9090 Forwarding from 0.0.0.0:9090 -> 9090 # Grafana UI root@dlp:~# microk8s kubectl port-forward -n monitoring service/grafana --address 0.0.0.0 3000:3000 Forwarding from 0.0.0.0:3000 -> 3000 |
[2] | ローカルネットワーク内の任意のクライアントコンピューターで Web ブラウザーを起動し、
[http://(MicroK8s プライマリーノードのホスト名 または IP アドレス):(設定したポート)/]
にアクセスして、Prometheus や Grafana の UI が表示されれば OK です。 なお、Grafana の [デフォルトユーザー/パスワード] は [admin/admin] です。ログイン後、直ちにパスワード変更を求められます。 |
Sponsored Link |