blade create k8s container-cpu

介绍

kubernetes 下 容器内 CPU 负载实验场景,同基础资源的 CPU 场景

命令

支持 CPU 场景命令如下:
    blade create k8s container-cpu load,容器内 CPU 负载场景,同 [blade create cpu load](blade create cpu load.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-pbnnc,容器id为 2ff814b246f86,做 CPU 负载 100% 实验举例。
yaml 配置方式
1
apiVersion: chaosblade.io/v1alpha1
2
kind: ChaosBlade
3
metadata:
4
name: increase-container-cpu-load-by-id
5
spec:
6
experiments:
7
- scope: container
8
target: cpu
9
action: fullload
10
desc: "increase container cpu load by id"
11
matchers:
12
- name: container-ids
13
value:
14
- "2ff814b246f86"
15
- name: cpu-percent
16
value: ["100"]
17
# pod names
18
- name: names
19
value: ["frontend-d89756ff7-pbnnc"]
Copied!
例如配置好文件后,保存为 increase_container_cpu_load_by_id.yaml,使用以下命令执行实验场景:
1
kubectl apply -f increase_container_cpu_load_by_id.yaml
Copied!
可通过以下命令查看每个实验的执行状态:
1
kubectl get blade increase-container-cpu-load-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": "increase-container-cpu-load-by-id",
10
"resourceVersion": "9432486",
11
"selfLink": "/apis/chaosblade.io/v1alpha1/chaosblades/increase-container-cpu-load-by-id",
12
"uid": "737ae2e8-ff79-11e9-a8e2-00163e08a39b"
13
},
14
"status": {
15
"expStatuses": [
16
{
17
"action": "fullload",
18
"resStatuses": [
19
{
20
"id": "2bcb4178003f46fe",
21
"kind": "container",
22
"name": "php-redis",
23
"nodeName": "cn-hangzhou.192.168.0.204",
24
"state": "Success",
25
"success": true,
26
"uid": "2ff814b246f86aba2392379640e4c6b16efbfd61846fc419a24f8d8ccf0f86f0"
27
}
28
],
29
"scope": "container",
30
"state": "Success",
31
"success": true,
32
"target": "cpu"
33
}
34
],
35
"phase": "Running"
36
}
37
}
Copied!
通过资源监控,可以看到此 Pod 下 CPU 使用情况
使用以下命令停止实验:
1
kubectl delete -f examples/increase_container_cpu_load_by_id.yaml
Copied!
blade 命令执行方式
1
blade create k8s container-cpu fullload --cpu-percent 100 --container-ids 2ff814b246f86 --names frontend-d89756ff7-pbnnc --namespace default --kubeconfig config
Copied!
如果执行失败,会返回详细的错误信息;如果执行成功,会返回实验的 UID:
1
{"code":200,"success":true,"result":"092e8b4d88d4f449"}
Copied!
可通过以下命令查询实验状态:
1
blade query k8s create 092e8b4d88d4f449 --kubeconfig config
2
3
{"code":200,"success":true,"result":{"uid":"092e8b4d88d4f449","success":true,"error":"","statuses":[{"id":"eab5fb70b61c9c45","uid":"2ff814b246f86aba2392379640e4c6b16efbfd61846fc419a24f8d8ccf0f86f0","name":"php-redis","state":"Success","kind":"container","success":true,"nodeName":"cn-hangzhou.192.168.0.204"}]}}
Copied!
销毁实验:
1
blade destroy 092e8b4d88d4f449
Copied!

常见问题

其他问题参考 [blade create k8s](blade create k8s.md) 常见问题
Last modified 4d ago