Kubernetes 使用 Weave Scope 监控集群(十七)

创建 Kubernetes 集群并部署容器化应用只是第一步。一旦集群运行起来,我们需要确保一起正常,所有必要组件就位并各司其职,有足够的资源满足应用的需求。Kubernetes 是一个复杂系统,运维团队需要有一套工具帮助他们获知集群的实时状态,并为故障排查提供及时和准确的数据支持。

一、安装

Weave Scope 是 Docker 和 Kubernetes 可视化监控工具。Scope 提供了至上而下的集群基础设施和应用的完整视图,用户可以轻松对分布式的容器化应用进行实时监控和问题诊断。
在 K8s 集群中安装 Scope 的方法很简单,使用下面的命令:

[root@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 created
serviceaccount/weave-scope created
clusterrole.rbac.authorization.k8s.io/weave-scope created
clusterrolebinding.rbac.authorization.k8s.io/weave-scope created
deployment.apps/weave-scope-app created
service/weave-scope-app created
daemonset.extensions/weave-scope-agent created

部署成功后,有如下相关组件:

[root@master ~]# kubectl get pod -n weave
NAME                               READY   STATUS    RESTARTS   AGE
weave-scope-agent-6l4wn            1/1     Running   0          4m55s
weave-scope-agent-dfpdl            1/1     Running   0          4m55s
weave-scope-agent-spxb4            1/1     Running   0          4m55s
weave-scope-app-6979884cc6-hpkdz   1/1     Running   0          4m55s
[root@master ~]# kubectl get svc -n weave
NAME              TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
weave-scope-app   NodePort   10.103.94.215   <none>        80:30229/TCP   5m
[root@master ~]# kubectl get deploy -n weave
NAME              READY   UP-TO-DATE   AVAILABLE   AGE
weave-scope-app   1/1     1            1           5m13s
  1. DaemonSet weave-scope-agent,集群每个节点上都会运行的 scope agent 程序,负责收集数据。
  2. Deployment weave-scope-app,scope 应用,从 agent 获取数据,通过 Web UI 展示并与用户交互。
  3. Service weave-scope-app,默认是 ClusterIP 类型,我们已经在上面的命令中添加了参数k8s-service-type=NodePort修改为 NodePort。

二、使用 Scope

浏览器访问 http://YOUR_MASTER_IP:30229/,Scope 默认显示当前所有的 Controller(Deployment、DaemonSet 等)。

Kubernetes 使用 Weave Scope 监控集群(十七)

2.1、拓扑结构

Scope 会自动构建应用和集群的逻辑拓扑。比如点击顶部 Pods,会显示所有 Pod 以及 Pod 之间的依赖关系。

Kubernetes 使用 Weave Scope 监控集群(十七)

点击 Hosts,会显示各个节点之间的关系,可以在 Scope 中查看资源的 CPU 和内存使用情况。

Kubernetes 使用 Weave Scope 监控集群(十七)

Kubernetes 使用 Weave Scope 监控集群(十七)

2.2、在线操作

Scope 还提供了便捷的在线操作功能,比如选中某个 Host,点击 &gt;_按钮可以直接在浏览器中打开节点的命令行终端:

Kubernetes 使用 Weave Scope 监控集群(十七)

点击 Deployment 的 + 可以执行 Scale Up 操作:

Kubernetes 使用 Weave Scope 监控集群(十七)

可以查看 Pod 的日志:

Kubernetes 使用 Weave Scope 监控集群(十七)

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

Kubernetes 使用 Weave Scope 监控集群(十七)

2.3、强大的搜索功能

Scope 支持关键字搜索和定位资源。

Kubernetes 使用 Weave Scope 监控集群(十七)

还可以进行条件搜索,比如查找和定位 MEMORY > 100M 的 Pod。

Kubernetes 使用 Weave Scope 监控集群(十七)

Weave Scope 界面极其友好,操作简洁流畅,更多功能留给大家去探索。

官方文档:https://www.weave.works/docs/scope/latest/installing/#k8s

猜你喜欢

转载自blog.51cto.com/wzlinux/2334210