blade create k8s pod-pod

介绍

kubernetes Pod 资源自身场景,比如删除 Pod

命令

支持的场景命令如下:
    blade create k8s pod-pod delete 删除 POD

参数

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

案例

删除指定 default 命名空间下标签是 app=guestbook 的 pod,删除
yaml配置方式如下
1
apiVersion: chaosblade.io/v1alpha1
2
kind: ChaosBlade
3
metadata:
4
name: delete-two-pod-by-labels
5
spec:
6
experiments:
7
- scope: pod
8
target: pod
9
action: delete
10
desc: "delete pod by labels"
11
matchers:
12
- name: labels
13
value:
14
- "app=guestbook"
15
- name: namespace
16
value:
17
- "default"
18
- name: evict-count
19
value:
20
- "2"
Copied!
保存文件为 delete_pod_by_labels.yaml,使用 kubectl apply -f delete_pod_by_labels.yaml 命令执行,可以看到执行前后,指定数量的 Pod 被杀掉后,又被重新拉起
通过 kubectl get blade delete-two-pod-by-labels -o json 可以查看详细的执行结果(下发只截取部分内容)
1
{
2
"apiVersion": "chaosblade.io/v1alpha1",
3
"kind": "ChaosBlade",
4
"metadata": {
5
"finalizers": [
6
"finalizer.chaosblade.io"
7
],
8
"generation": 1,
9
"name": "delete-two-pod-by-labels",
10
"resourceVersion": "9423460",
11
"selfLink": "/apis/chaosblade.io/v1alpha1/chaosblades/delete-two-pod-by-labels",
12
"uid": "f31da567-ff71-11e9-a8e2-00163e08a39b"
13
},
14
"status": {
15
"expStatuses": [
16
{
17
"action": "delete",
18
"resStatuses": [
19
{
20
"kind": "pod",
21
"name": "frontend-d89756ff7-94fj6",
22
"nodeName": "cn-hangzhou.192.168.0.203",
23
"state": "Success",
24
"success": true,
25
"uid": "79cd691c-fe3a-11e9-8883-00163e0ad0b3"
26
},
27
{
28
"kind": "pod",
29
"name": "frontend-d89756ff7-dkgmd",
30
"nodeName": "cn-hangzhou.192.168.0.205",
31
"state": "Success",
32
"success": true,
33
"uid": "79d1f47e-fe3a-11e9-8883-00163e0ad0b3"
34
}
35
],
36
"scope": "pod",
37
"state": "Success",
38
"success": true,
39
"target": "pod"
40
}
41
],
42
"phase": "Running"
43
}
44
}
Copied!
执行以下命令停止实验:
1
kubectl delete -f delete_pod_by_labels.yaml
Copied!
或者直接删除 blade 资源:
1
kubectl delete blade delete-two-pod-by-labels
Copied!
删除 Pod 的停止实验操作,chaosblade 本身不会重新拉起被删除的 Pod,只是去更改实验状态!!
blade 执行方式
1
blade create k8s pod-pod delete --labels app=guestbook --namespace default --evict-count 2 --kubeconfig config
Copied!
如果执行失败,会返回详细的错误信息;如果执行成功,会返回实验的 UID:
1
{"code":200,"success":true,"result":"4d3caa0a99c3b2dd"}
Copied!
可通过以下命令查询实验状态:
1
blade query k8s create 4d3caa0a99c3b2dd --kubeconfig config
2
3
{"code":200,"success":true,"result":{"uid":"4d3caa0a99c3b2dd","success":true,"error":"","statuses":[{"uid":"f325d43c-ff71-11e9-8883-00163e0ad0b3","name":"frontend-d89756ff7-5wgg5","state":"Success","kind":"pod","success":true,"nodeName":"cn-hangzhou.192.168.0.203"},{"uid":"28af19dd-f987-11e9-bd30-00163e08a39b","name":"frontend-d89756ff7-dpv7h","state":"Success","kind":"pod","success":true,"nodeName":"cn-hangzhou.192.168.0.205"}]}}
Copied!
销毁实验:
1
blade destroy 4d3caa0a99c3b2dd
Copied!

常见问题

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