iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 25
0

普羅米修斯 (Prometheus) 是一個可以提供 Kubernetes 應用程式量測的開源套件, 一方面可以彙整量測資訊, 也可以提供警告 (Alert) 通知.
本篇筆記將介紹如何安裝與使用 Prometheus 套件

使用 Prometheus 進行 Kubernetes 量測

  1. https://github.com/helm/charts fork chart
    https://ithelp.ithome.com.tw/upload/images/20181103/20111871I0esJYZt5o.png
  2. git clone https://github.com/[yourgithub]/charts 到本機
  3. 使用 Helm 命令 helm install stable/prometheus --name pro-demo -f .\stable\pachyderm\values.yaml 安裝 Prometheus
PS C:\k8s\charts> helm install stable/prometheus --name pro-demo -f .\stable\pachyderm\values.yaml
NAME:   pro-demo
LAST DEPLOYED: Thu Nov  1 00:07:34 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1beta1/ClusterRoleBinding
NAME                                    AGE
pro-demo-prometheus-kube-state-metrics  0s
pro-demo-prometheus-server              0s

==> v1beta1/DaemonSet

NAME                               DESIRED  CURRENT  READY  UP-TO-DATE  AVAILABLE  NODE SELECTOR  AGE
pro-demo-prometheus-node-exporter  1        1        0      1           0          <none>         0s

==> v1beta1/Deployment

NAME                                    DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
pro-demo-prometheus-alertmanager        1        1        1           0          0s
pro-demo-prometheus-kube-state-metrics  1        1        1           0          0s
pro-demo-prometheus-pushgateway         1        1        1           0          0s
pro-demo-prometheus-server              1        1        1           0          0s

==> v1/ConfigMap

NAME                              DATA  AGE
pro-demo-prometheus-alertmanager  1     0s
pro-demo-prometheus-server        3     0s

==> v1/PersistentVolumeClaim

NAME                              STATUS   VOLUME    CAPACITY  ACCESS MODES  STORAGECLASS  AGE
pro-demo-prometheus-alertmanager  Pending  hostpath  0s
pro-demo-prometheus-server        Pending  hostpath  0s

==> v1/ServiceAccount

NAME                                    SECRETS  AGE
pro-demo-prometheus-alertmanager        1        0s
pro-demo-prometheus-kube-state-metrics  1        0s
pro-demo-prometheus-node-exporter       1        0s
pro-demo-prometheus-pushgateway         1        0s
pro-demo-prometheus-server              1        0s

==> v1beta1/ClusterRole

NAME                                    AGE
pro-demo-prometheus-kube-state-metrics  0s
pro-demo-prometheus-server              0s

==> v1/Service

NAME                                    TYPE       CLUSTER-IP      EXTERNAL-IP  PORT(S)   AGE
pro-demo-prometheus-alertmanager        ClusterIP  10.110.141.9    <none>       80/TCP    0s
pro-demo-prometheus-kube-state-metrics  ClusterIP  None            <none>       80/TCP    0s
pro-demo-prometheus-node-exporter       ClusterIP  None            <none>       9100/TCP  0s
pro-demo-prometheus-pushgateway         ClusterIP  10.102.160.186  <none>       9091/TCP  0s
pro-demo-prometheus-server              ClusterIP  10.108.221.100  <none>       80/TCP    0s

==> v1/Pod(related)

NAME                                                     READY  STATUS             RESTARTS  AGE
pro-demo-prometheus-node-exporter-84xpx                  0/1    ContainerCreating  0         0s
pro-demo-prometheus-alertmanager-5bbb765fbf-mf99t        0/2    Pending            0         0s
pro-demo-prometheus-kube-state-metrics-6768486fc6-6xwt4  0/1    ContainerCreating  0         0s
pro-demo-prometheus-pushgateway-6d75b58669-2vhxc         0/1    ContainerCreating  0         0s
pro-demo-prometheus-server-6b78f68f-449pw                0/2    Pending            0         0s

NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
pro-demo-prometheus-server.default.svc.cluster.local

Get the Prometheus server URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace default port-forward $POD_NAME 9090

The Prometheus alertmanager can be accessed via port 80 on the following DNS name from within your cluster:
pro-demo-prometheus-alertmanager.default.svc.cluster.local

Get the Alertmanager URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace default port-forward $POD_NAME 9093

The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster:
pro-demo-prometheus-pushgateway.default.svc.cluster.local

Get the PushGateway URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace default port-forward $POD_NAME 9091

For more information on running Prometheus, visit:
https://prometheus.io/
  1. 使用命令 kubectl get pods --namespace default -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}", 取得 pod 名稱
PS C:\k8s\charts> kubectl get pods --namespace default -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}"
pro-demo-prometheus-server-6b78f68f-s2l94
  1. 使用命令 kubectl --namespace default port-forward pro-demo-prometheus-server-6b78f68f-s2l94 9090 設定 prometheus-server listen 9090 port
PS C:\k8s\charts> kubectl --namespace default port-forward pro-demo-prometheus-server-6b78f68f-s2l94 9090
Forwarding from 127.0.0.1:9090 -> 9090
Forwarding from [::1]:9090 -> 9090
  1. 開啟 **http://localhost:9090** 進入 prometheus 首頁
  2. 執行 process_cpu_seconds_total 取得量測資料
    https://ithelp.ithome.com.tw/upload/images/20181103/20111871qKAmm2grBb.png
  3. 選取 Graph 顯示數值圖
    https://ithelp.ithome.com.tw/upload/images/20181103/20111871sYwVidOTql.png

參考資料:


上一篇
Day 24 - 使用 Helm 部署應用程式到 Kubernetes
下一篇
Day 26 - 安裝使用分散式跟蹤系統 - Jaeger
系列文
15 分鐘學習系列 - 第一次學 Kubernetes 就上手30

尚未有邦友留言

立即登入留言