Skip to content

Commit fc2e174

Browse files
authored
Merge pull request #47506 from my-git9/2024-06-21-custom-profiling-kubectl-debug
[zh-cn] Add blog: 2024-06-21-custom-profiling-kubectl-debug.md
2 parents a4d8c11 + cb2d70f commit fc2e174

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
layout: blog
3+
title: "Kubernetes 1.31:kubectl debug 中的自定义模板化配置特性已进入 Beta 阶段"
4+
date: 2024-08-22
5+
slug: kubernetes-1-31-custom-profiling-kubectl-debug
6+
author: >
7+
Arda Güçlü (Red Hat)
8+
translator: >
9+
Xin Li (DaoCloud)
10+
---
11+
<!--
12+
layout: blog
13+
title: "Kubernetes 1.31: Custom Profiling in Kubectl Debug Graduates to Beta"
14+
date: 2024-08-22
15+
slug: kubernetes-1-31-custom-profiling-kubectl-debug
16+
author: >
17+
Arda Güçlü (Red Hat)
18+
-->
19+
20+
<!--
21+
There are many ways of troubleshooting the pods and nodes in the cluster. However, `kubectl debug` is one of the easiest, highly used and most prominent ones. It
22+
provides a set of static profiles and each profile serves for a different kind of role. For instance, from the network administrator's point of view,
23+
debugging the node should be as easy as this:
24+
-->
25+
有很多方法可以对集群中的 Pod 和节点进行故障排查,而 `kubectl debug` 是最简单、使用最广泛、最突出的方法之一。
26+
它提供了一组静态配置,每个配置适用于不同类型的角色。
27+
例如,从网络管理员的视角来看,调试节点应该像这样简单:
28+
29+
```shell
30+
$ kubectl debug node/mynode -it --image=busybox --profile=netadmin
31+
```
32+
33+
<!--
34+
On the other hand, static profiles also bring about inherent rigidity, which has some implications for some pods contrary to their ease of use.
35+
Because there are various kinds of pods (or nodes) that all have their specific
36+
necessities, and unfortunately, some can't be debugged by only using the static profiles.
37+
38+
Take an instance of a simple pod consisting of a container whose healthiness relies on an environment variable:
39+
-->
40+
另一方面,静态配置也存在固有的刚性,对某些 Pod 所产生的影响与其易用性是相悖的。
41+
因为各种类型的 Pod(或节点)都有其特定的需求,不幸的是,有些问题仅通过静态配置是无法调试的。
42+
43+
以一个简单的 Pod 为例,此 Pod 由一个容器组成,其健康状况依赖于环境变量:
44+
45+
```yaml
46+
apiVersion: v1
47+
kind: Pod
48+
metadata:
49+
name: example-pod
50+
spec:
51+
containers:
52+
- name: example-container
53+
image: customapp:latest
54+
env:
55+
- name: REQUIRED_ENV_VAR
56+
value: "value1"
57+
```
58+
59+
<!--
60+
Currently, copying the pod is the sole mechanism that supports debugging this pod in kubectl debug. Furthermore, what if user needs to modify the `REQUIRED_ENV_VAR` to something different
61+
for advanced troubleshooting?. There is no mechanism to achieve this.
62+
-->
63+
目前,复制 Pod 是使用 `kubectl debug` 命令调试此 Pod 的唯一机制。
64+
此外,如果用户需要将 `REQUIRED_ENV_VAR` 环境变量修改为其他不同值来进行高级故障排查,
65+
当前并没有机制能够实现这一需求。
66+
67+
<!--
68+
## Custom Profiling
69+
70+
Custom profiling is a new functionality available under `--custom` flag, introduced in kubectl debug to provide extensibility. It expects partial `Container` spec in either YAML or JSON format.
71+
In order to debug the example-container above by creating an ephemeral container, we simply have to define this YAML:
72+
-->
73+
## 自定义模板化配置
74+
75+
自定义模板化配置使用 `--custom` 标志提供的一项新特性,在 `kubectl debug` 中引入以提供可扩展性。
76+
它需要以 YAML 或 JSON 格式的内容填充 `container` 规约,
77+
为了通过创建临时容器来调试上面的示例容器,我们只需定义此 YAML:
78+
79+
```yaml
80+
# partial_container.yaml
81+
env:
82+
- name: REQUIRED_ENV_VAR
83+
value: value2
84+
```
85+
86+
<!--
87+
and execute:
88+
-->
89+
并且执行:
90+
91+
```shell
92+
kubectl debug example-pod -it --image=customapp --custom=partial_container.yaml
93+
```
94+
95+
<!--
96+
Here is another example that modifies multiple fields at once (change port number, add resource limits, modify environment variable) in JSON:
97+
-->
98+
下面是另一个在 JSON 中一次修改多个字段(更改端口号、添加资源限制、修改环境变量)的示例:
99+
100+
```json
101+
{
102+
"ports": [
103+
{
104+
"containerPort": 80
105+
}
106+
],
107+
"resources": {
108+
"limits": {
109+
"cpu": "0.5",
110+
"memory": "512Mi"
111+
},
112+
"requests": {
113+
"cpu": "0.2",
114+
"memory": "256Mi"
115+
}
116+
},
117+
"env": [
118+
{
119+
"name": "REQUIRED_ENV_VAR",
120+
"value": "value2"
121+
}
122+
]
123+
}
124+
```
125+
126+
<!--
127+
## Constraints
128+
129+
Uncontrolled extensibility hurts the usability. So that, custom profiling is not allowed for certain fields such as command, image, lifecycle, volume devices and container name.
130+
In the future, more fields can be added to the disallowed list if required.
131+
-->
132+
## 约束
133+
134+
不受控制的扩展性会损害可用性。因此,某些字段(例如命令、镜像、生命周期、卷设备和容器名称)不允许进行自定义模版化配置。
135+
将来如果需要,可以将更多字段添加到禁止列表中。
136+
137+
<!--
138+
## Limitations
139+
140+
The `kubectl debug` command has 3 aspects: Debugging with ephemeral containers, pod copying, and node debugging. The largest intersection set of these aspects is the container spec within a Pod
141+
That's why, custom profiling only supports the modification of the fields that are defined with `containers`. This leads to a limitation that if user needs to modify the other fields in the Pod spec, it is not supported.
142+
-->
143+
## 限制
144+
145+
`kubectl debug` 命令有 3 个方面:使用临时容器进行调试、Pod 复制和节点调试。
146+
这些方面最大的交集是 Pod 内的容器规约,因此自定义模版化配置仅支持修改使用 `containers` 下定义的字段。
147+
这导致了一个限制,如果用户需要修改 Pod 规约中的其他字段,则不受支持。
148+
149+
<!--
150+
## Acknowledgments
151+
152+
Special thanks to all the contributors who reviewed and commented on this feature, from the initial conception to its actual implementation (alphabetical order):
153+
-->
154+
## 致谢
155+
156+
特别感谢所有审查和评论此特性(从最初的概念到实际实施)的贡献者(按字母顺序排列):
157+
158+
- [Eddie Zaneski](https://github.com/eddiezane)
159+
- [Maciej Szulik](https://github.com/soltysh)
160+
- [Lee Verberne](https://github.com/verb)

0 commit comments

Comments
 (0)