为了账号安全,请及时绑定邮箱和手机立即绑定

K8s可视化监控之-Weave Scope

标签:
运维工具

一 背景

在生成环境中k8s应用部署众多,需要一款可视化工具方便日常获知集群的实时状态,并为故障排查提供及时和准确的数据支持。在此背景下,Weaveworks的项目Weave Scope 应运而生,其是一款 Docker 和 Kubernetes 可视化监控工具。Scope 提供了至上而下的集群基础设施和应用的完整视图,用户可以轻松对分布式的容器化应用进行实时监控和问题诊断,以确保容器应用程序的稳定性和性能,通过查看容器上下文的度量/标记,以及原数据,在容器内部的进程之间可以轻松的确定运行服务消耗最多CPU/内存资源的容器,

二 组件详解

2.1 功能

Weave Scope可以监控kubernetes集群中的一系列资源的状态、资源使用情况、应用拓扑、scale、还可以直接通过浏览器进入容器内部调试等,其提供的功能包括:

  • 交互式拓扑界面
  • 图形模式和表格模式
  • 过滤功能
  • 搜索功能
  • 实时度量
  • 容器排错
  • 插件扩展

2.2 组成

Weave Scope由App和Probe两部分组成:

  • Probe Agent负责收集容器和宿主的信息,并发送给 App

  • App 负责处理这些信息,并生成相应的报告,并以交互界面的形式展示

2.3 部署模式

  1. weave-scope-agent,集群每个节点上都会运行的 scope agent 程序,负责收集数据,其部署为DaemonSet模式。
  2. weave-scope-app,scope 应用,从 agent 获取数据,通过 Web UI 展示并与用户交互,其部署为Deployment模式。
  3. weave-scope-app,默认是 ClusterIP 类型,为了方便已通过 kubectl edit 修改为 NodePort

三 安装部署

3.1 Node节点部署

最初Weave Scope可以在运行Docker容器的宿主机进行安装部署

sudo curl -L git.io/scope -o /usr/local/bin/scope
sudo chmod a+x /usr/local/bin/scope
scope launch

之后访问http://宿主机IP:4040进行访问

3.2 K8s 资源文件部署

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

# 修改svc 为NodePort
kubectl patch svc $(kubectl get svc -n weave |grep weave-scope-app |awk '{print $1}') -p '{"spec":{"type": "NodePort"}}' -n weave


[root@master ~]# kubectl get svc -n weave |grep weave-scope-app 
weave-scope-app   NodePort   10.96.244.177   <none>        80:30156/TCP   52s

# 查看weave 的pod
[root@master ~]# kubectl get pod -n weave -o wide
NAME                                         READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
weave-scope-agent-49csj                      1/1     Running   0          7m58s   10.234.2.204   master   <none>           <none>
weave-scope-agent-lxjkb                      1/1     Running   0          7m58s   10.234.2.132   node1    <none>           <none>
weave-scope-agent-wp22d                      1/1     Running   0          7m58s   10.234.2.160   node2    <none>           <none>
weave-scope-app-85966885c8-9gf86             1/1     Running   0          7m59s   10.244.2.246   node2    <none>           <none>
weave-scope-cluster-agent-5c9765fff6-hsl9r   1/1     Running   0          7m58s   10.244.2.247   node2    <none>           <none>

3.2 helm 部署

目前helm 仓库提供了weave-scope编写好的charts,可以fetch到本地,进行简单的修改即可安装,非常方便快捷

[root@master common-service]# helm fetch stable/weave-scope
[root@master common-service]# tar -zxvf weave-scope-1.1.8.tgz
[root@master common-service]# sed -i "s@\ type:\ \"ClusterIP\"@ type: \"NodePort\"@" weave-scope/values.yaml 

[root@master common-service]# helm install -n weave-scope --namespace common-service -f weave-scope/values.yaml weave-scope/
NAME:   weave-scope
LAST DEPLOYED: Thu Jan 30 18:37:14 2020
NAMESPACE: common-service
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                           DATA  AGE
weave-scope-weave-scope-tests  1     1s

==> v1/DaemonSet
NAME                           DESIRED  CURRENT  READY  UP-TO-DATE  AVAILABLE  NODE SELECTOR  AGE
weave-scope-agent-weave-scope  4        4        0      4           0          <none>         1s

==> v1/Deployment
NAME                                   READY  UP-TO-DATE  AVAILABLE  AGE
weave-scope-cluster-agent-weave-scope  0/1    1           0          1s
weave-scope-frontend-weave-scope       0/1    1           0          1s

==> v1/Pod(related)
NAME                                                    READY  STATUS             RESTARTS  AGE
weave-scope-agent-weave-scope-5xskf                     0/1    ContainerCreating  0         1s
weave-scope-agent-weave-scope-76t2s                     0/1    ContainerCreating  0         1s
weave-scope-agent-weave-scope-qb74g                     0/1    ContainerCreating  0         1s
weave-scope-agent-weave-scope-zggff                     0/1    ContainerCreating  0         1s
weave-scope-cluster-agent-weave-scope-5b8bf77f5f-7jkhq  0/1    ContainerCreating  0         1s
weave-scope-frontend-weave-scope-6d985ccff6-xmz2d       0/1    ContainerCreating  0         1s

==> v1/Service
NAME                     TYPE      CLUSTER-IP   EXTERNAL-IP  PORT(S)       AGE
weave-scope-weave-scope  NodePort  10.233.41.4  <none>       80:31709/TCP  1s

==> v1/ServiceAccount
NAME                                   SECRETS  AGE
weave-scope-cluster-agent-weave-scope  1        1s

==> v1beta1/ClusterRole
NAME                                   AGE
weave-scope-cluster-agent-weave-scope  1s

==> v1beta1/ClusterRoleBinding
NAME                     AGE
weave-scope-weave-scope  1s


NOTES:
You should now be able to access the Scope frontend in your web browser, by
going to the address or hostname of any node in the cluster, using http 
and the port given by:

SCOPE_PORT=$(kubectl -n common-service get svc weave-scope-weave-scope \
-o jsonpath='{.spec.ports[?(@.name==http)].nodePort}'); echo $SCOPE_PORT

Most likely one or more of the URLs given by this pipeline will work:

SCOPE_PORT=$(kubectl -n common-service get svc  \
-o jsonpath='{.spec.ports[?(@.name==http)].nodePort}'); \
kubectl get nodes -o jsonpath='{.items[0].status.addresses[*].address}' | \
xargs -I{} -d" " echo http://{}:$SCOPE_PORT
For more details on using Weave Scope, see the Weave Scope documentation:

https://www.weave.works/docs/scope/latest/introducing/

四 使用

4.1 资源对象查看

在此以POD资源对象为例,Weave Scope监控对象有进程、容器、pods、主机等,监控项有cpu、内存、平均负载等。

4.1.1 图表方式

图片描述

4.1.2 表格方式

图片描述

4.2 对象资源使用情况

点击某个pod,会展示状态、资源使用、进程等详细信息

图片描述

4.3 日志信息

点击具体POD的get logs弹出Terminal窗口查看日志

图片描述

4.4 描述信息

点击具体POD上的describe通过Terminal来查看POD资源信息

图片描述

4.5 资源伸缩

点击deployment类型的Controllers,可以来web界面来扩展或缩小以及查看POD的数量及详细信息。

图片描述

4.6 容器操作

可以对容器进行attach、exec shell、restart、paus和stop操作以及容器日志查看

图片描述

4.7 条件查询

左下角可按条件展示,有容器类型(系统或者应用)、容器状态(停止或者运行)、命名空间等。

图片描述

4.8 搜索功能

4.8.1 名称

图片描述

4.8.2 资源使用率

图片描述

五 反思

  • weave scope可以以其简洁的可视化为我们更生动形象的展现出service/controller/pod等资源对象的管理及简单的web ui操作,方便故障排除及时定位
  • weave scope作为web ui目前缺少登录验证,可以利用其他方式里面web服务器的验证做安全管控。

参考链接

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
全栈工程师
手记
粉丝
6495
获赞与收藏
191

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消