Skip to content

Commit 6796294

Browse files
authored
Refine documents (#37)
* Refine documents Signed-off-by: Aylei <[email protected]> * Fix gif link * Fix ref link Signed-off-by: Aylei <[email protected]>
1 parent caff131 commit 6796294

File tree

3 files changed

+130
-70
lines changed

3 files changed

+130
-70
lines changed

README.md

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Go Report Card](https://goreportcard.com/badge/github.com/aylei/kubectl-debug)](https://goreportcard.com/report/github.com/aylei/kubectl-debug)
66
[![docker](https://img.shields.io/docker/pulls/aylei/debug-agent.svg)](https://hub.docker.com/r/aylei/debug-agent)
77

8-
[中文](./docs/zh-cn.md)
8+
[简体中文](/docs/zh-cn.md)
99

1010
# Overview
1111

@@ -15,33 +15,18 @@
1515
- [quick start](#quick-start)
1616
- [build from source](#build-from-source)
1717
- [port-forward and agentless](#port-forward-mode-And-agentless-mode)
18-
- [configuration](#configurations)
19-
- [future works](#future-works)
20-
- [implementation details](#details)
18+
- [configuration](#configuration)
19+
- [roadmap](#roadmap)
20+
- [authorization](#authorization)
2121
- [contribute](#contribute)
2222

2323
# Screenshots
2424

25-
![gif](./docs/kube-debug.gif)
25+
![gif](/docs/kube-debug.gif)
2626

2727
# Quick Start
2828

29-
`kubectl-debug` is pretty simple, give it a try!
30-
31-
Install the debug agent DaemonSet in your cluster, which is responsible for running the "debug container":
32-
33-
```bash
34-
kubectl apply -f https://raw.githubusercontent.com/aylei/kubectl-debug/master/scripts/agent_daemonset.yml
35-
# or using helm
36-
helm install -n=debug-agent ./contrib/helm/kubectl-debug
37-
```
38-
39-
Install the kubectl debug plugin:
40-
41-
Using [krew](https://github.com/kubernetes-sigs/krew):
42-
```shell
43-
# Waiting the krew index PR to be merged...
44-
```
29+
## Install the kubectl debug plugin
4530

4631
Homebrew:
4732
```shell
@@ -62,11 +47,28 @@ sudo mv kubectl-debug /usr/local/bin/
6247

6348
For windows users, download the latest archive from the [release page](https://github.com/aylei/kubectl-debug/releases/tag/v0.1.0), decompress the package and add it to your PATH.
6449

50+
## (Optional) Install the debug agent DaemonSet
51+
52+
`kubectl-debug` requires an agent pod to communicate with the container runtime. In the [agentless mode](#port-forward-mode-And-agentless-mode), the agent pod can be created when a debug session starts and to be cleaned up when the session ends.
53+
54+
While convenient, creating pod before debugging can be time consuming. You can install the debug agent DaemonSet in advance to skip this:
55+
56+
```bash
57+
kubectl apply -f https://raw.githubusercontent.com/aylei/kubectl-debug/master/scripts/agent_daemonset.yml
58+
# or using helm
59+
helm install -n=debug-agent ./contrib/helm/kubectl-debug
60+
```
61+
62+
## Debug instructions
63+
6564
Try it out!
65+
6666
```bash
6767
# kubectl 1.12.0 or higher
6868
kubectl debug -h
69-
kubectl debug POD_NAME
69+
# you can omit --agentless to reduce start time if you have installed the debug agent daemonset
70+
# we will omit this flag in the following commands
71+
kubectl debug POD_NAME --agentless
7072

7173
# in case of your pod stuck in `CrashLoopBackoff` state and cannot be connected to,
7274
# you can fork a new pod and diagnose the problem in the forked pod
@@ -77,10 +79,10 @@ kubectl debug POD_NAME --port-forward --daemonset-ns=kube-system --daemonset-nam
7779

7880
# old versions of kubectl cannot discover plugins, you may execute the binary directly
7981
kubect-debug POD_NAME
80-
8182
```
8283

83-
Any trouble? [file and issue for help](https://github.com/aylei/kubectl-debug/issues/new)
84+
* You can configure the default arguments to simplify usage, refer to [Configuration](#configuration)
85+
* Refer to [Examples](/docs/examples.md) for practical debugging examples
8486

8587
# Build from source
8688

@@ -101,11 +103,10 @@ make agent-docker
101103

102104
- `port-foward` mode: By default, `kubectl-debug` will directly connect with the target host. When `kubectl-debug` cannot connect to `targetHost:agentPort`, you can enable `port-forward` mode. In `port-forward` mode, the local machine listens on `localhost:agentPort` and forwards data to/from `targetPod:agentPort`.
103105

104-
105106
- `agentless` mode: By default, `debug-agent` needs to be pre-deployed on each node of the cluster, which consumes cluster resources all the time. Unfortunately, debugging Pod is a low-frequency operation. To avoid loss of cluster resources, the `agentless` mode has been added in [#31](https://github.com/aylei/kubectl-debug/pull/31). In `agentless` mode, `kubectl-debug` will first start `debug-agent` on the host where the target Pod is located, and then `debug-agent` starts the debug container. After the user exits, `kubectl-debug` will delete the debug container and `kubectl-debug` will delete the `debug-agent` pod at last.
106107

107108

108-
# Configurations
109+
# Configuration
109110

110111
`kubectl-debug` uses [nicolaka/netshoot](https://github.com/nicolaka/netshoot) as the default image to run debug container, and use `bash` as default entrypoint.
111112

@@ -152,35 +153,25 @@ If the debug-agent is not accessible from host port, it is recommended to set `p
152153

153154
PS: `kubectl-debug` will always override the entrypoint of the container, which is by design to avoid users running an unwanted service by mistake(of course you can always do this explicitly).
154155

155-
# Roadmap
156-
157-
`kubectl-debug` is supposed to be just a troubleshooting helper, and is going be replaced by the native `kubectl debug` command when [this proposal](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/node/troubleshoot-running-pods.md) is implemented and merged in the future kubernetes release. But for now, there is still some works to do to improve `kubectl-debug`.
158-
159-
If you are interested in any of following features, please file an issue to avoid potential duplication.
160-
161-
- [ ] Security. `kubectl-debug` runs privileged agent on every node, and client talks to the agent directly. A possible solution is introducing a central apiserver to do RBAC, which integrates to the kube apiserver using [aggregation layer](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation/)
162-
- [ ] Protocol. `kubectl-debug` vendor the SPDY wrapper from `client-go`. SPDY is deprecated now, websockets may be a better choice
163-
- [ ] e2e tests.
156+
# Authorization
164157

165-
# Details
158+
Currently, `kubectl-debug` reuse the privilege of the `pod/exec` sub resource to do authorization, which means that it has the same privilege requirements with the `kubectl exec` command.
166159

167-
`kubectl-debug` consists of 2 components:
160+
# Roadmap
168161

169-
* the kubectl plugin: a cli client of `node agent`, serves `kubectl debug` command,
170-
* the node agent: responsible for manipulating the "debug container"; node agent will also act as a websockets relay for remote tty
162+
`kubectl-debug` is supposed to be just a troubleshooting helper, and is going be replaced by the native `kubectl debug` command when [this proposal](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/node/troubleshoot-running-pods.md) is implemented and merged in the future kubernetes release. But for now, there is still some works to do to improve `kubectl-debug`.
171163

172-
When user run `kubectl debug target-pod -c <container-name> /bin/bash`:
164+
- [ ] Security: Currently, `kubectl-debug` do authorization in the client-side, which should be moved to the server-side (debug-agent)
165+
- [ ] More unit tests
166+
- [ ] More real world debugging example
167+
- [ ] e2e tests
173168

174-
1. The plugin gets the pod info from apiserver and extract the `hostIP`, if the target container does not exist or is not currently running, an error is raised.
175-
2. The plugin sends an HTTP request to the specific node agent running on the `hostIP`, which includes a protocol upgrade from HTTP to SPDY.
176-
3. The agent runs a container in the pod's namespaces (ipc, pid, network, etc) with the STDIN stay open (`-i` flag).
177-
4. The agent checks if the target container is actively running, if not, write an error to client.
178-
5. The agent runs a `debug container` with `tty` and `stdin` opened, the `debug container` will join the `pid`, `network`, `ipc` and `user` namespace of the target container.
179-
6. The agent pipes the connection into the `debug container` using `attach`
180-
7. **Debug in the debug container**.
181-
8. Job is done, user closes the SPDY connection.
182-
9. The node agent closes the SPDY connection, then waits for the `debug container` to exit and do the cleanup.
169+
If you are interested in any of the above features, please file an issue to avoid potential duplication.
183170

184171
# Contribute
185172

186173
Feel free to open issues and pull requests. Any feedback is highly appreciated!
174+
175+
# Acknowledgement
176+
177+
This project would not be here without the effort of [our contributors](https://github.com/aylei/kubectl-debug/graphs/contributors), thanks!

docs/design.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Under the hood
2+
3+
`kubectl-debug` consists of 2 components:
4+
5+
* the kubectl plugin: a cli client of `node agent`, serves `kubectl debug` command,
6+
* the node agent: responsible for manipulating the "debug container"; node agent will also act as a websockets relay for remote tty
7+
8+
When user run `kubectl debug target-pod -c <container-name> /bin/bash`:
9+
10+
1. The plugin gets the pod info from apiserver and extract the `hostIP`, if the target container does not exist or is not currently running, an error is raised.
11+
2. The plugin sends an HTTP request to the specific node agent running on the `hostIP`, which includes a protocol upgrade from HTTP to SPDY.
12+
3. The agent runs a container in the pod's namespaces (ipc, pid, network, etc) with the STDIN stay open (`-i` flag).
13+
4. The agent checks if the target container is actively running, if not, write an error to client.
14+
5. The agent runs a `debug container` with `tty` and `stdin` opened, the `debug container` will join the `pid`, `network`, `ipc` and `user` namespace of the target container.
15+
6. The agent pipes the connection into the `debug container` using `attach`
16+
7. **Debug in the debug container**.
17+
8. Job is done, user closes the SPDY connection.
18+
9. The node agent closes the SPDY connection, then waits for the `debug container` to exit and do the cleanup.

docs/zh-cn.md

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
# Kubectl debug
22

3+
![license](https://img.shields.io/hexpm/l/plug.svg)
4+
[![travis](https://travis-ci.org/aylei/kubectl-debug.svg?branch=master)](https://travis-ci.org/aylei/kubectl-debug)
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/aylei/kubectl-debug)](https://goreportcard.com/report/github.com/aylei/kubectl-debug)
6+
[![docker](https://img.shields.io/docker/pulls/aylei/debug-agent.svg)](https://hub.docker.com/r/aylei/debug-agent)
7+
8+
[English](/README.md)
9+
10+
# Overview
11+
312
`kubectl-debug` 是一个简单的 kubectl 插件, 能够帮助你便捷地进行 Kubernetes 上的 Pod 排障诊断. 背后做的事情很简单: 在运行中的 Pod 上额外起一个新容器, 并将新容器加入到目标容器的 `pid`, `network`, `user` 以及 `ipc` namespace 中, 这时我们就可以在新容器中直接用 `netstat`, `tcpdump` 这些熟悉的工具来解决问题了, 而旧容器可以保持最小化, 不需要预装任何额外的排障工具.
413

5-
# Quick Start
14+
- [截图](#截图)
15+
- [快速开始](#快速开始)
16+
- [构建项目](#构建项目)
17+
- [port-forward 和 agentless 模式](#port-forward-模式和-agentless-模式)
18+
- [配置](#配置)
19+
- [权限](#权限)
20+
- [路线图](#路线图)
21+
- [贡献代码](#贡献代码)
622

7-
`kubectl-debug` 包含两部分, 一部分是用户侧的 kubectl 插件, 另一部分是部署在所有 k8s 节点上的 agent(用于启动"新容器", 同时也作为 SPDY 连接的中继). 因此首先要部署 agent.
8-
```bash
9-
kubectl apply -f https://raw.githubusercontent.com/aylei/kubectl-debug/master/scripts/agent_daemonset.yml
10-
# 或者使用 helm 安装
11-
helm install -n=debug-agent ./contrib/helm/kubectl-debug
12-
```
23+
# 截图
1324

14-
安装 kubectl 插件:
25+
![gif](/docs/kube-debug.gif)
1526

16-
使用 [krew](https://github.com/kubernetes-sigs/krew):
17-
```shell
18-
# Waiting the krew index PR to be merged...
19-
```
27+
# 快速开始
28+
29+
## 安装 kubectl debug 插件
30+
31+
安装 kubectl 插件:
2032

2133
使用 Homebrew:
2234
```shell
@@ -37,26 +49,50 @@ sudo mv kubectl-debug /usr/local/bin/
3749

3850
Windows 用户可以从 [release page](https://github.com/aylei/kubectl-debug/releases/tag/v0.1.0) 进行下载并添加到 PATH 中
3951

52+
## (可选) 安装 debug-agent DaemonSet
53+
54+
`kubectl-debug` 包含两部分, 一部分是用户侧的 kubectl 插件, 另一部分是部署在所有 k8s 节点上的 agent(用于启动"新容器", 同时也作为 SPDY 连接的中继). 在 `agentless` 中, `kubectl-debug` 会在 debug 开始时创建 debug-agent Pod, 并在结束后自动清理.
55+
56+
`agentless` 虽然方便, 但会让 debug 的启动速度显著下降, 你可以通过预先安装 debug-agent 的 DaemonSet 来使用 agent 模式, 加快启动速度:
57+
58+
```bash
59+
kubectl apply -f https://raw.githubusercontent.com/aylei/kubectl-debug/master/scripts/agent_daemonset.yml
60+
# 或者使用 helm 安装
61+
helm install -n=debug-agent ./contrib/helm/kubectl-debug
62+
```
63+
4064
简单使用:
4165
```bash
42-
# kubectl 1.12.0 or higher
66+
# kubectl 1.12.0 或更高的版本, 可以直接使用:
4367
kubectl debug -h
44-
kubectl debug POD_NAME
68+
# 假如安装了 debug-agent 的 daemonset, 可以略去 --agentless 来加快启动速度
69+
# 之后的命令里会略去 --agentless
70+
kubectl debug POD_NAME --agentless
4571

46-
# in case of your pod stuck in `CrashLoopBackoff` state and cannot be connected to,
47-
# you can fork a new pod and diagnose the problem in the forked pod
72+
# 假如 Pod 处于 CrashLookBackoff 状态无法连接, 可以复制一个完全相同的 Pod 来进行诊断
4873
kubectl debug POD_NAME --fork
4974

50-
# if the node ip is not directly accessible, try port-forward mode
75+
# 假如 Node 没有公网 IP 或无法直接访问(防火墙等原因), 请使用 port-forward 模式
5176
kubectl debug POD_NAME --port-forward --daemonset-ns=kube-system --daemonset-name=debug-agent
5277

53-
# old versions of kubectl cannot discover plugins, you may execute the binary directly
78+
# 老版本的 kubectl 无法自动发现插件, 需要直接调用 binary
5479
kubect-debug POD_NAME
55-
5680
```
5781

58-
Any trouble? [file and issue for help](https://github.com/aylei/kubectl-debug/issues/new)
82+
# 构建项目
5983

84+
克隆仓库, 然后执行:
85+
```bash
86+
# make will build plugin binary and debug-agent image
87+
make
88+
# install plugin
89+
mv kubectl-debug /usr/local/bin
90+
91+
# build plugin only
92+
make plugin
93+
# build agent only
94+
make agent-docker
95+
```
6096

6197
# port-forward 模式和 agentless 模式
6298

@@ -65,7 +101,7 @@ Any trouble? [file and issue for help](https://github.com/aylei/kubectl-debug/is
65101
- `agentless`模式: 默认情况下,`debug-agent`需要预先部署在集群每个节点上,会一直消耗集群资源,然而调试 Pod 是低频操作。为避免集群资源损失,在[#31](https://github.com/aylei/kubectl-debug/pull/31)增加了`agentless`模式。`agentless`模式下,`kubectl-debug`会先在目标Pod所在宿主机上启动`debug-agent`,然后再启动调试容器。用户调试结束后,`kubectl-debug`会依次删除调试容器和在目的主机启动的`degbug-agent`
66102

67103

68-
# 默认镜像和 Entrypoint
104+
# 配置
69105

70106
`kubectl-debug` 使用 [nicolaka/netshoot](https://github.com/nicolaka/netshoot) 作为默认镜像. 默认镜像和指令都可以通过命令行参数进行覆盖. 考虑到每次都指定有点麻烦, 也可以通过文件配置的形式进行覆盖, 编辑 `~/.kube/debug-config` 文件:
71107

@@ -107,3 +143,18 @@ command:
107143
```
108144
109145
> `kubectl-debug` 会将容器的 entrypoint 直接覆盖掉, 这是为了避免在 debug 时不小心启动非 shell 进程.
146+
147+
# 权限
148+
149+
目前, `kubectl-debug` 复用了 `pod/exec` 资源的权限来做鉴权. 也就是说, `kubectl-debug` 的权限要求是和 `kubectl exec` 一致的.
150+
151+
# 路线图
152+
153+
- [ ] 安全: 目前, `kubectl-debug` 是在客户端做鉴权的, 这部分应当被移动到服务端(debug-agent) 中
154+
- [ ] 更多的单元测试
155+
- [ ] 更多的故障诊断实例
156+
- [ ] e2e 测试
157+
158+
# 贡献代码
159+
160+
欢迎贡献代码或 issue!

0 commit comments

Comments
 (0)