天天看點

k8s部署weave scope可視化工具

Weave Scope 是一款 Docker 和 Kubernetes 的可視化監控工具。它提供了自上而下的應用程式視圖以及整個基礎架構視圖,使用者可以輕松對分布式的容器化應用進行實時監控和問題診斷,以確定容器應用程式的穩定性和性能。

Weave Scope 可以監控 Kubernetes 叢集中的一系列資源的狀态、資源使用情況、應用拓撲、scale,還可以通過浏覽器直接進入容器内部調試等。其提供的功能包括:

互動式拓撲界面

圖形模式和表格模式

過濾功能

搜尋功能

實時度量

容器排錯

插件擴充
           

Weave Scope 由

App

Probe Agent

兩部分組成:

Probe Agent:負責收集容器和宿主的資訊,發送給App

App:負責處理收集的資訊,生成相應報告,并以互動界面的形式展示
           

官網:https://www.weave.works/ ,最新版本:1.13.1

k8s以DaemonSet方式部署 scope agent,以Deployment方式部署 scope app:

weave-scope.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: weave

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: weave-scope
  namespace: weave
  labels:
    name: weave-scope

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: weave-scope
  labels:
    name: weave-scope
rules:
  - apiGroups:
      - ''
    resources:
      - pods
    verbs:
      - get
      - list
      - watch
      - delete
  - apiGroups:
      - ''
    resources:
      - pods/log
      - services
      - nodes
      - namespaces
      - persistentvolumes
      - persistentvolumeclaims
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - apps
    resources:
      - deployments
      - daemonsets
      - statefulsets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - batch
    resources:
      - cronjobs
      - jobs
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - extensions
    resources:
      - deployments
      - daemonsets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - apps
    resources:
      - deployments/scale
    verbs:
      - get
      - update
  - apiGroups:
      - extensions
    resources:
      - deployments/scale
    verbs:
      - get
      - update
  - apiGroups:
      - storage.k8s.io
    resources:
      - storageclasses
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - volumesnapshot.external-storage.k8s.io
    resources:
      - volumesnapshots
      - volumesnapshotdatas
    verbs:
      - list
      - watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: weave-scope
  labels:
    name: weave-scope
roleRef:
  kind: ClusterRole
  name: weave-scope
  apiGroup: rbac.authorization.k8s.io
subjects:
  - kind: ServiceAccount
    name: weave-scope
    namespace: weave

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: weave-scope
  namespace: weave
spec:
  rules:
    - host: scope.lzxlinux.com
      http:
        paths:
          - path: /
            backend:
              serviceName: weave-scope-app
              servicePort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: weave-scope-app
  namespace: weave
  labels:
    name: weave-scope-app
    app: weave-scope
    weave-cloud-component: scope
    weave-scope-component: app
spec:
  ports:
    - name: app
      port: 80
      protocol: TCP
      targetPort: 4040
  selector:
    name: weave-scope-app
    app: weave-scope
    weave-cloud-component: scope
    weave-scope-component: app
    
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: weave-scope-app
  namespace: weave
  labels:
    name: weave-scope-app
    app: weave-scope
    weave-cloud-component: scope
    weave-scope-component: app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: weave-scope-app
      app: weave-scope
      weave-cloud-component: scope
      weave-scope-component: app
  template:
    metadata:
      labels:
        name: weave-scope-app
        app: weave-scope
        weave-cloud-component: scope
        weave-scope-component: app
    spec:
      containers:
        - name: app
          image: docker.io/weaveworks/scope:1.13.1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 4040
              protocol: TCP
          args:
            - '--mode=app'
          command:
            - /home/weave/scope
          env: []

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: weave-scope-cluster-agent
  namespace: weave
  labels:
    name: weave-scope-cluster-agent
    app: weave-scope
    weave-cloud-component: scope
    weave-scope-component: cluster-agent
spec:
  replicas: 1
  selector:
    matchLabels:
      name: weave-scope-cluster-agent
      app: weave-scope
      weave-cloud-component: scope
      weave-scope-component: cluster-agent
  template:
    metadata:
      labels:
        name: weave-scope-cluster-agent
        app: weave-scope
        weave-cloud-component: scope
        weave-scope-component: cluster-agent
    spec:
      serviceAccountName: weave-scope
      containers:
        - name: scope-cluster-agent
          image: docker.io/weaveworks/scope:1.13.1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 4041
              protocol: TCP
          args:
            - '--mode=probe'
            - '--probe-only'
            - '--probe.kubernetes.role=cluster'
            - '--probe.http.listen=:4041'
            - '--probe.publish.interval=4500ms'
            - '--probe.spy.interval=2s'
            - 'weave-scope-app.weave.svc.cluster.local:80'
          command:
            - /home/weave/scope
          env: []
          resources:
            limits:
              memory: 2000Mi
            requests:
              cpu: 25m
              memory: 80Mi

---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: weave-scope-agent
  namespace: weave
  labels:
    name: weave-scope-agent
    app: weave-scope
    weave-cloud-component: scope
    weave-scope-component: agent
spec:
  updateStrategy:
    type: RollingUpdate
  minReadySeconds: 5
  selector:
    matchLabels:
      name: weave-scope-agent
      app: weave-scope
      weave-cloud-component: scope
      weave-scope-component: agent
  template:
    metadata:
      labels:
        name: weave-scope-agent
        app: weave-scope
        weave-cloud-component: scope
        weave-scope-component: agent
    spec:
      containers:
        - name: scope-agent
          image: docker.io/weaveworks/scope:1.13.1
          imagePullPolicy: IfNotPresent
          args:
            - '--mode=probe'
            - '--probe-only'
            - '--probe.kubernetes.role=host'
            - '--probe.publish.interval=4500ms'
            - '--probe.spy.interval=2s'
            - '--probe.docker.bridge=docker0'
            - '--probe.docker=true'
            - 'weave-scope-app.weave.svc.cluster.local:80'
          command:
            - /home/weave/scope
          env: []
          resources:
            limits:
              memory: 2000Mi
            requests:
              cpu: 100m
              memory: 100Mi
          securityContext:
            privileged: true
          volumeMounts:
            - name: scope-plugins
              mountPath: /var/run/scope/plugins
            - name: sys-kernel-debug
              mountPath: /sys/kernel/debug
            - name: docker-socket
              mountPath: /var/run/docker.sock
      volumes:
        - name: scope-plugins
          hostPath:
            path: /var/run/scope/plugins
        - name: sys-kernel-debug
          hostPath:
            path: /sys/kernel/debug
        - name: docker-socket
          hostPath:
            path: /var/run/docker.sock
      dnsPolicy: ClusterFirstWithHostNet
      hostNetwork: true
      hostPID: true
      tolerations:
        - effect: NoSchedule
          operator: Exists
        - effect: NoExecute
          operator: Exists
           
  • 部署:
kubectl apply -f weave-scope.yaml
           
kubectl get svc -n weave

NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
weave-scope-app   ClusterIP   10.106.124.95   <none>        80/TCP    25s

kubectl get pod -n weave

NAME                                        READY   STATUS    RESTARTS   AGE
weave-scope-agent-27zpb                     1/1     Running   0          32s
weave-scope-agent-c5hcq                     1/1     Running   0          32s
weave-scope-agent-j4tf7                     1/1     Running   0          32s
weave-scope-agent-s8p6s                     1/1     Running   0          32s
weave-scope-app-bc7444d59-6xwkk             1/1     Running   0          33s
weave-scope-cluster-agent-5c5dcc8cb-4d7mh   1/1     Running   0          33s
           
  • 通路ui:

添加hosts:

scope.lzxlinux.com

,通路

scope.lzxlinux.com

k8s部署weave scope可視化工具

可以看到,目前k8s叢集有4個節點(1個master,3個node)。

  • ui操作:

以pod資源對象為例,Weave Scope監控對象有程序、容器、pods、主機等,監控項有cpu、記憶體、平均負載等。

圖形模式,

k8s部署weave scope可視化工具

表格模式,

k8s部署weave scope可視化工具

點選某個pod,會展示狀态、資源使用、程序等詳細資訊,

k8s部署weave scope可視化工具

點選pod的

Get logs

,會打開Terminal檢視日志,

k8s部署weave scope可視化工具

點選pod的

Describe

,會打開Terminal檢視資源資訊(類似

kubectl describe

指令),

k8s部署weave scope可視化工具

點選

Controllers

,對于Deployment,可以直接擴縮容以及檢視POD的數量和詳細資訊,

k8s部署weave scope可視化工具

點選

Containers

,可以對容器進行

attach

exec shell

restart

pause

stop

操作,

k8s部署weave scope可視化工具

此外,左下角可按條件展示,如命名空間、容器類型(系統或應用)、容器狀态(停止或運作)等,

k8s部署weave scope可視化工具

同時,搜尋欄可以按條件搜尋相應的資源對象,如命名空間、對象類型、對象名稱、image及版本、運作狀态、資源使用率等,

k8s部署weave scope可視化工具

至此,k8s部署weave scope完成。已存放至個人github:kubernetes

繼續閱讀