<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 使用Prometheus監控kubernetes集群 我們使用 Giantswarm 開源的 [kubernetes-promethues](https://github.com/giantswarm/kubernetes-prometheus) 來監控 kubernetes 集群,所有的 YAML 文件可以在 [../manifests/prometheus](https://github.com/rootsongjc/kubernetes-handbook/blob/master/manifests/prometheus) 目錄下找到。 需要用到的鏡像有: - harbor-001.jimmysong.io/library/prometheus-alertmanager:v0.7.1 - harbor-001.jimmysong.io/library/grafana:4.2.0 - harbor-001.jimmysong.io/library/giantswarm-tiny-tools:latest - harbor-001.jimmysong.io/library/prom-prometheus:v1.7.0 - harbor-001.jimmysong.io/library/kube-state-metrics:v1.0.1 - harbor-001.jimmysong.io/library/dockermuenster-caddy:0.9.3 - harbor-001.jimmysong.io/library/prom-node-exporter:v0.14.0 同時備份到時速云: - index.tenxcloud.com/jimmy/prometheus-alertmanager:v0.7.1 - index.tenxcloud.com/jimmy/grafana:4.2.0 - index.tenxcloud.com/jimmy/giantswarm-tiny-tools:latest - index.tenxcloud.com/jimmy/prom-prometheus:v1.7.0 - index.tenxcloud.com/jimmy/kube-state-metrics:v1.0.1 - index.tenxcloud.com/jimmy/dockermuenster-caddy:0.9.3 - index.tenxcloud.com/jimmy/prom-node-exporter:v0.14.0 **注**:所有鏡像都是從官方鏡像倉庫下載下。 ## 部署 我將部署時需要用的的配置文件分成了 namespace、serviceaccount、configmaps、clusterrolebinding 和最后的部署 prometheus、grafana 的過程。 ```yaml ## 創建 monitoring namespaece kubectl create -f prometheus-monitoring-ns.yaml ## 創建 serviceaccount kubectl create -f prometheus-monitoring-serviceaccount.yaml ## 創建 configmaps kubectl create -f prometheus-configmaps.yaml ## 創建 clusterrolebinding kubectl create clusterrolebinding kube-state-metrics --clusterrole=cluster-admin --serviceaccount=monitoring:kube-state-metrics kubectl create clusterrolebinding prometheus --clusterrole=cluster-admin --serviceaccount=monitoring:prometheus ## 部署 Prometheus kubectl create -f prometheus-monitoring.yaml ``` 訪問 kubernetes 任何一個 node 上的 Grafana service 的 nodeport: ![Grafana頁面](https://box.kancloud.cn/254ab1b19f4289b01c4058d21743f0cf_1870x981.jpg) 該圖中的數據顯示明顯有問題,還需要修正。 `prometheus-monitoring.yaml` 文件中有一個 Job 就是用來導入 grafana dashboard 配置信息的,如果該 Job 執行失敗,可以單獨在在 `monitoring` 的 namespace 中啟動一個容器,將 `manifests/prometheus` 目錄下的 json 文件復制到容器中,然后進入容器 json 文件的目錄下執行: ```bash for file in *-datasource.json ; do if [ -e "$file" ] ; then echo "importing $file" && curl --silent --fail --show-error \ --request POST http://admin:admin@grafana:3000/api/datasources \ --header "Content-Type: application/json" \ --data-binary "@$file" ; echo "" ; fi done ; for file in *-dashboard.json ; do if [ -e "$file" ] ; then echo "importing $file" && ( echo '{"dashboard":'; \ cat "$file"; \ echo ',"overwrite":true,"inputs":[{"name":"DS_PROMETHEUS","type":"datasource","pluginId":"prometheus","value":"prometheus"}]}' ) \ | jq -c '.' \ | curl --silent --fail --show-error \ --request POST http://admin:admin@grafana:3000/api/dashboards/import \ --header "Content-Type: application/json" \ --data-binary "@-" ; echo "" ; fi done ``` 這樣也可以向 grafana 中導入 dashboard。 ## 存在的問題 該項目的代碼中存在幾個問題。 ### 1. RBAC 角色授權問題 需要用到兩個 clusterrolebinding: - `kube-state-metrics`,對應的`serviceaccount`是`kube-state-metrics` - `prometheus`,對應的 `serviceaccount`是 `prometheus-k8s` 在部署 Prometheus 之前應該先創建 serviceaccount、clusterrole、clusterrolebinding 等對象,否則在安裝過程中可能因為權限問題而導致各種錯誤,所以這些配置應該寫在一個單獨的文件中,而不應該跟其他部署寫在一起,即使要寫在一個文件中,也應該寫在文件的最前面,因為使用 `kubectl` 部署的時候,kubectl 不會判斷 YAML 文件中的資源依賴關系,只是簡單的從頭部開始執行部署,因此寫在文件前面的對象會先部署。 **解決方法** 也可以繞過復雜的 RBAC 設置,直接使用下面的命令將對應的 serviceaccount 設置成 admin 權限,如下: ```bash kubectl create clusterrolebinding kube-state-metrics --clusterrole=cluster-admin --serviceaccount=monitoring:kube-state-metrics kubectl create clusterrolebinding prometheus --clusterrole=cluster-admin --serviceaccount=monitoring:prometheus ``` 參考 [RBAC——基于角色的訪問控制](../guide/rbac.md) ### 2. API 兼容問題 從 `kube-state-metrics` 日志中可以看出用戶 kube-state-metrics 沒有權限訪問如下資源類型: - *v1.Job - *v1.PersistentVolumeClaim - *v1beta1.StatefulSet - *v2alpha1.CronJob 而在我們使用的 kubernetes 1.6.0 版本的集群中 API 路徑跟 `kube-state-metrics` 中不同,無法 list 以上三種資源對象的資源。詳情見:https://github.com/giantswarm/kubernetes-prometheus/issues/77 ### 3. Job 中的權限認證問題 在 `grafana-import-dashboards` 這個 job 中有個 `init-containers` 其中指定的 command 執行錯誤,應該使用 ```bash curl -sX GET -H "Authorization:bearer `cat /var/run/secrets/kubernetes.io/serviceaccount/token`" -k https://kubernetes.default/api/v1/namespaces/monitoring/endpoints/grafana ``` 不需要指定 csr 文件,只需要 token 即可。 參考 [wait-for-endpoints init-containers fails to load with k8s 1.6.0 #56](https://github.com/giantswarm/kubernetes-prometheus/issues/56) ## 參考 - [Kubernetes Setup for Prometheus and Grafana](https://github.com/giantswarm/kubernetes-prometheus) - [RBAC——基于角色的訪問控制](../guide/rbac.md) - [wait-for-endpoints init-containers fails to load with k8s 1.6.0 #56](https://github.com/giantswarm/kubernetes-prometheus/issues/56)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看