Skip to content

Latest commit

 

History

History
111 lines (78 loc) · 4.48 KB

File metadata and controls

111 lines (78 loc) · 4.48 KB

排错工具

本章主要介绍在 Kubernetes 排错中常用的工具。

必备工具

  • kubectl:用于查看 Kubernetes 集群状态
  • journalctl:用于查看 Kubernetes 组件日志
  • iptables:用于排查 Service 是否工作
  • tcpdump:用于排查容器网络问题

sysdig

sysdig 是一个容器排错工具,提供了开源和商业版本。对于常规排错来说,使用开源版本即可。

除了 sysdig,还可以使用其他两个辅助工具

  • csysdig:与 sysdig 一起自动安装,提供了一个命令行界面

  • sysdig-inspect:为 sysdig 保存的跟踪文件(如 sudo sysdig -w filename.scap)提供了一个图形界面(非实时)

安装

# on Linux
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash

# on MacOS
brew install sysdig

示例

# Refer https://www.sysdig.org/wiki/sysdig-examples/.
# View the top network connections for a single container
sysdig -pc -c topconns

# Show the network data exchanged with the host 192.168.0.1
sysdig -s2000 -A -c echo_fds fd.cip=192.168.0.1
 
# List all the incoming connections that are not served by apache.
sysdig -p"%proc.name %fd.name" "evt.type=accept and proc.name!=httpd"

# View the CPU/Network/IO usage of the processes running inside the container.
sysdig -pc -c topprocs_cpu container.id=2e854c4525b8
sysdig -pc -c topprocs_net container.id=2e854c4525b8
sysdig -pc -c topfiles_bytes container.id=2e854c4525b8

# See the files where apache spends the most time doing I/O
sysdig -c topfiles_time proc.name=httpd

# Show all the interactive commands executed inside a given container.
sysdig -pc -c spy_users 

# Show every time a file is opened under /etc.
sysdig evt.type=open and fd.name 

Weave Scope

Weave Scope 是另外一款可视化容器监控和排错工具。与 sysdig 相比,它没有强大的命令行工具,但提供了一个简单易用的交互界面,自动描绘了整个集群的拓扑,并可以通过插件扩展其功能。从其官网的介绍来看,其提供的功能包括

Weave Scope 由 App 和 Probe 两部分组成,它们

  • Probe 负责收集容器和宿主的信息,并发送给 App
  • App 负责处理这些信息,并生成相应的报告,并以交互界面的形式展示
                    +--Docker host----------+      +--Docker host----------+
.---------------.   |  +--Container------+  |      |  +--Container------+  |
| Browser       |   |  |                 |  |      |  |                 |  |
|---------------|   |  |  +-----------+  |  |      |  |  +-----------+  |  |
|               |----->|  | scope-app |<-----.    .----->| scope-app |  |  |
|               |   |  |  +-----------+  |  | \  / |  |  +-----------+  |  |
|               |   |  |        ^        |  |  \/  |  |        ^        |  |
'---------------'   |  |        |        |  |  /\  |  |        |        |  |
                    |  | +-------------+ |  | /  \ |  | +-------------+ |  |
                    |  | | scope-probe |-----'    '-----| scope-probe | |  |
                    |  | +-------------+ |  |      |  | +-------------+ |  |
                    |  |                 |  |      |  |                 |  |
                    |  +-----------------+  |      |  +-----------------+  |
                    +-----------------------+      +-----------------------+

安装

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

安装完成后,可以通过 weave-scope-app 来访问交互界面

kubectl -n weave get service weave-scope-app

点击 Pod,还可以查看该 Pod 所有容器的实时状态和度量数据: