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
添加hosts:scope.lzxlinux.com
,访问scope.lzxlinux.com
可以看到,当前k8s集群有4个节点(1个master,3个node)。
以pod资源对象为例,Weave Scope监控对象有进程、容器、pods、主机等,监控项有cpu、内存、平均负载等。
图形模式,
表格模式,
点击某个pod,会展示状态、资源使用、进程等详细信息,
点击pod的Get logs
,会打开Terminal查看日志,
点击pod的Describe
,会打开Terminal查看资源信息(类似 kubectl describe
命令),
点击Controllers
,对于Deployment,可以直接扩缩容以及查看POD的数量和详细信息,
点击Containers
,可以对容器进行 attach
、exec shell
、restart
、pause
、stop
操作,
此外,左下角可按条件展示,如命名空间、容器类型(系统或应用)、容器状态(停止或运行)等,
同时,搜索栏可以按条件搜索相应的资源对象,如命名空间、对象类型、对象名称、image及版本、运行状态、资源使用率等,
至此,k8s部署weave scope完成。已存放至个人github:kubernetes