天天看點

k8s之Weave Scope監控

用 Weave Scope 監控叢集

建立 Kubernetes 叢集并部署容器化應用隻是第一步。一旦叢集運作起來,我們需要確定一起正常,所有必要元件就位并各司其職,有足夠的資源滿足應用的需求。Kubernetes 是一個複雜系統,運維團隊需要有一套工具幫助他們獲知叢集的實時狀态,并為故障排查提供及時和準确的資料支援。

Kubernetes 常用的監控方案

Weave Scope

Weave Scope 是 Docker 和 Kubernetes 可視化監控工具。Scope 提供了至上而下的叢集基礎設施和應用的完整視圖,使用者可以輕松對分布式的容器化應用進行實時監控和問題診斷。

安裝 Scope

安裝 Scope 的方法很簡單,執行如下指令:

kubectl apply -f "https://cloud.weave.works/k8s/scope.yaml?k8s-version=$(kubectl version | base64 | tr -d '\n')&k8s-service-type=NodePort"

部署成功後,有如下相關元件:

[root@k8s-master ~]# kubectl apply -f "https://cloud.weave.works/k8s/scope.yaml?k8s-version=$(kubectl version | base64 | tr -d '\n')&k8s-service-type=NodePort"
namespace/weave unchanged
serviceaccount/weave-scope created
clusterrole.rbac.authorization.k8s.io/weave-scope configured
clusterrolebinding.rbac.authorization.k8s.io/weave-scope configured
deployment.apps/weave-scope-app created
service/weave-scope-app created
deployment.apps/weave-scope-cluster-agent created
daemonset.apps/weave-scope-agent created
[root@k8s-master ~]# kubectl get pod -n weave
NAME                                         READY   STATUS              RESTARTS   AGE
weave-scope-agent-bct26                      1/1     Running             0          30s
weave-scope-agent-vzdbr                      0/1     ContainerCreating   0          30s
weave-scope-agent-xvwsp                      0/1     ContainerCreating   0          30s
weave-scope-app-cf544d8c4-v9x5z              1/1     Running             0          30s
weave-scope-cluster-agent-6466d94ccf-r4vql   0/1     ContainerCreating   0          30s
[root@k8s-master ~]# kubectl get pod -n weave
NAME                                         READY   STATUS    RESTARTS   AGE
weave-scope-agent-bct26                      1/1     Running   0          57s
weave-scope-agent-vzdbr                      1/1     Running   0          57s
weave-scope-agent-xvwsp                      1/1     Running   0          57s
weave-scope-app-cf544d8c4-v9x5z              1/1     Running   0          57s
weave-scope-cluster-agent-6466d94ccf-r4vql   1/1     Running   0          57s
[root@k8s-master ~]# kubectl get svc -n weave 
NAME              TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
weave-scope-app   NodePort   10.108.59.226   <none>        80:31013/TCP   68s
[root@k8s-master ~]# kubectl get deployments. -n weave 
NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
weave-scope-app             1/1     1            1           81s
weave-scope-cluster-agent   1/1     1            1           80s           

DaemonSet weave-scope-agent,叢集每個節點上都會運作的 scope agent 程式,負責收集資料。

Deployment weave-scope-app,scope 應用,從 agent 擷取資料,通過 Web UI 展示并與使用者互動。

Service weave-scope-app,預設是 ClusterIP 類型,已經在上面的指令中添加了參數k8s-service-type=NodePort修改為 NodePort。

使用 Scope

浏覽器通路 http://192.168.56.106:31013/,Scope 預設顯示目前所有的 Controller(Deployment、DaemonSet 等)。

k8s之Weave Scope監控

拓撲結構

Scope 會自動建構應用和叢集的邏輯拓撲。比如點選頂部 PODS,會顯示所有 Pod 以及 Pod 之間的依賴關系。

k8s之Weave Scope監控

點選 HOSTS,會顯示各個節點之間的關系。

k8s之Weave Scope監控

實時資源監控

可以在 Scope 中檢視資源的 CPU 和記憶體使用情況。

k8s之Weave Scope監控

支援的資源有 Host、Pod 和 Container。

k8s之Weave Scope監控
k8s之Weave Scope監控

線上操作

Scope 還提供了便捷的線上操作功能,比如選中某個 Host,點選 >_ 按鈕可以直接在浏覽器中打開節點的指令行終端:

k8s之Weave Scope監控

點選 Deployment 的 + 可以執行 Scale Up 操作:

可以檢視 Pod 的日志:

k8s之Weave Scope監控

可以 attach、restart、stop 容器,以及直接在 Scope 中排查問題:

k8s之Weave Scope監控

強大的搜尋功能

繼續閱讀