blade create k8s container-process

介绍

kubernetes 下 容器内进程场景,同基础资源的进程场景

命令

支持的进程场景命令如下:
    blade create k8s container-process kill 杀容器内指定进程,同 [blade create process kill](blade create process kill.md)
    blade create k8s container-process stop 挂起容器内指定进程,同 [blade create process stop](blade create process stop.md)

参数

除了上述基础场景各自所需的参数外,在 kubernetes 环境下,还支持的参数如下:
1
--container-ids string 容器ID,支持配置多个
2
--container-names string 容器名称,支持配置多个
3
--docker-endpoint string Docker server 地址,默认为本地的 /var/run/docker.sock
4
--namespace string Pod 所属的命名空间,只能填写一个值,必填项
5
--evict-count string 限制实验生效的数量
6
--evict-percent string 限制实验生效数量的百分比,不包含 %
7
--labels string Pod 资源标签,多个标签之前是或的关系
8
--names string Pod 资源名
9
--kubeconfig string kubeconfig 文件全路径(仅限使用 blade 命令调用时使用)
10
--waiting-time string 实验结果等待时间,默认为 20s,参数值要包含单位,例如 10s,1m
Copied!

案例

指定 default 命名空间下 Pod 名是 frontend-d89756ff7-tl4xl,容器id为 f1de335b4eeaf,进程名为 top 的进程。
yaml 配置方式
1
apiVersion: chaosblade.io/v1alpha1
2
kind: ChaosBlade
3
metadata:
4
name: kill-container-process-by-id
5
spec:
6
experiments:
7
- scope: container
8
target: process
9
action: kill
10
desc: "kill container process by id"
11
matchers:
12
- name: container-ids
13
value:
14
- "f1de335b4eeaf"
15
- name: process
16
value: ["top"]
17
- name: names
18
value: ["frontend-d89756ff7-tl4xl"]
Copied!
例如配置好文件后,保存为 kill_container_process_by_id.yaml ,使用以下命令执行实验场景:
1
kubectl apply -f kill_container_process_by_id.yaml
Copied!
可通过以下命令查看每个实验的执行状态:
1
kubectl get blade kill-container-process-by-id -o json
Copied!
1
{
2
"apiVersion": "chaosblade.io/v1alpha1",
3
"kind": "ChaosBlade",
4
"metadata": {
5
"finalizers": [
6
"finalizer.chaosblade.io"
7
],
8
"generation": 1,
9
"name": "kill-container-process-by-id",
10
"resourceVersion": "9438733",
11
"selfLink": "/apis/chaosblade.io/v1alpha1/chaosblades/kill-container-process-by-id",
12
"uid": "a5a597be-ff7e-11e9-a8e2-00163e08a39b"
13
},
14
"status": {
15
"expStatuses": [
16
{
17
"action": "kill",
18
"resStatuses": [
19
{
20
"id": "10cdc57b9c80a9f0",
21
"kind": "container",
22
"name": "php-redis",
23
"nodeName": "cn-hangzhou.192.168.0.204",
24
"state": "Success",
25
"success": true,
26
"uid": "f1de335b4eeaf035b8d23a87080f3d24cebc803cbb6ad15e5fe0d8567e2e8939"
27
}
28
],
29
"scope": "container",
30
"state": "Success",
31
"success": true,
32
"target": "process"
33
}
34
],
35
"phase": "Running"
36
}
37
}
Copied!
使用以下命令停止实验:
1
kubectl delete -f kill_container_process_by_id.yaml
Copied!
注意,停止实验不会恢复已杀掉的进程!!
blade 命令执行方式
1
blade create k8s container-process kill --process top --names frontend-d89756ff7-tl4xl --container-ids f1de335b4eeaf --namespace default --kubeconfig config
Copied!
如果执行失败,会返回详细的错误信息;如果执行成功,会返回实验的 UID:
1
{"code":200,"success":true,"result":"06d5ebae60e8fe3f"}
Copied!
可通过以下命令查询实验状态:
1
blade query k8s create 06d5ebae60e8fe3f --kubeconfig config
2
3
{"code":200,"success":true,"result":{"uid":"06d5ebae60e8fe3f","success":true,"error":"","statuses":[{"id":"1000cbd2018e2c90","uid":"f1de335b4eeaf035b8d23a87080f3d24cebc803cbb6ad15e5fe0d8567e2e8939","name":"php-redis","state":"Success","kind":"container","success":true,"nodeName":"cn-hangzhou.192.168.0.204"}]}}
Copied!
销毁实验:
1
blade destroy 06d5ebae60e8fe3f
Copied!

常见问题

Q: 如果状态如下:
1
"status": {
2
"expStatuses": [
3
{
4
"action": "kill",
5
"error": "see resStatus for the error details",
6
"resStatuses": [
7
{
8
"kind": "container",
9
"name": "slave",
10
"nodeName": "cn-hangzhou.192.168.0.204",
11
"state": "Error",
12
"success": false,
13
"uid": "c3175f916e87fe06c339712427758f3d51dcb38d3e71cfae168bbbdfeab86710"
14
}
15
],
16
"scope": "container",
17
"state": "Error",
18
"success": false,
19
"target": "process"
20
}
21
],
22
"phase": "Error"
23
}
Copied!
A: 其实已经执行,只是返回结果有乱码;删除实验,重新执行实验即可
Q:
1
"status": {
2
"expStatuses": [
3
{
4
"action": "kill",
5
"error": "the resources not found",
6
"scope": "container",
7
"state": "Error",
8
"success": false,
9
"target": "process"
10
}
11
],
12
"phase": "Error"
13
}
Copied!
A: container 没有找到
Q:
1
"status": {
2
"expStatuses": [
3
{
4
"action": "kill",
5
"error": "see resStatus for the error details",
6
"resStatuses": [
7
{
8
"error": "top process not found exit status 1",
9
"kind": "container",
10
"name": "php-redis",
11
"nodeName": "cn-hangzhou.192.168.0.204",
12
"state": "Error",
13
"success": false,
14
"uid": "f1de335b4eeaf035b8d23a87080f3d24cebc803cbb6ad15e5fe0d8567e2e8939"
15
}
16
],
17
"scope": "container",
18
"state": "Error",
19
"success": false,
20
"target": "process"
21
}
22
],
23
"phase": "Error"
24
}
Copied!
A:目标进程找不到
其他问题参考 [blade create k8s](blade create k8s.md) 常见问题
Last modified 4d ago