blade create k8s pod-network

介绍

kubernetes Pod网络相关场景,同基础资源的网络场景

命令

支持的网络场景命令如下:
    blade create k8s pod-network delay Pod 网络延迟场景,同 [blade create network delay](blade create network delay.md)
    blade create k8s pod-network loss Pod 网络丢包场景,同 [blade create network loss](blade create network loss.md)
    blade create k8s pod-network dns Pod 域名访问异常场景,同 [blade create network dns](blade create network dns.md)

参数

除了上述场景各自所需的参数外,在 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 命名空间下,指定名为 redis-slave-674d68586-jnf7f Pod本地端口 6379 访问延迟 3000 毫秒,延迟时间上下浮动 1000 毫秒
yaml 配置方式
1
apiVersion: chaosblade.io/v1alpha1
2
kind: ChaosBlade
3
metadata:
4
name: delay-pod-network-by-names
5
spec:
6
experiments:
7
- scope: pod
8
target: network
9
action: delay
10
desc: "delay pod network by names"
11
matchers:
12
- name: names
13
value:
14
- "redis-slave-674d68586-jnf7f"
15
- name: namespace
16
value:
17
- "default"
18
- name: local-port
19
value: ["6379"]
20
- name: interface
21
value: ["eth0"]
22
- name: time
23
value: ["3000"]
24
- name: offset
25
value: ["1000"]
Copied!
保存为 yaml 文件,比如 delay_pod_network_by_names.yaml,使用 kubectl 命令执行:
1
kubectl apply -f delay_pod_network_by_names.yaml
Copied!
实验状态查询:
1
kubectl get blade delay-pod-network-by-names -o json
Copied!
返回结果如下(省略了一部分):
1
{
2
"apiVersion": "v1",
3
"items": [
4
{
5
"apiVersion": "chaosblade.io/v1alpha1",
6
"kind": "ChaosBlade",
7
"metadata": {
8
"finalizers": [
9
"finalizer.chaosblade.io"
10
],
11
"generation": 1,
12
"name": "delay-pod-network-by-names",
13
"resourceVersion": "9425766",
14
"selfLink": "/apis/chaosblade.io/v1alpha1/chaosblades/delay-pod-network-by-names",
15
"uid": "cf32327c-ff73-11e9-b3be-00163e136d88"
16
},
17
"status": {
18
"expStatuses": [
19
{
20
"action": "delay",
21
"resStatuses": [
22
{
23
"id": "e28f6e3ae2732a86",
24
"kind": "pod",
25
"name": "chaosblade-tool-vv49t", // 此pod为sidecar
26
"nodeName": "cn-hangzhou.192.168.0.204",
27
"state": "Success",
28
"success": true,
29
"uid": "4f1a28a1-fee6-11e9-8883-00163e0ad0b3"
30
}
31
],
32
"scope": "pod",
33
"state": "Success",
34
"success": true,
35
"target": "network"
36
}
37
],
38
"phase": "Running"
39
}
40
}
41
],
42
}
Copied!
可通过访问服务,或者 telnet 命令验证实验效果
执行以下命令停止实验:
1
kubectl delete -f delay_pod_network_by_names.yaml
Copied!
或者直接删除 blade 资源:
1
kubectl delete blade delay-pod-network-by-names
Copied!
blade 执行方式
1
blade create k8s pod-network delay --time 3000 --offset 1000 --interface eth0 --local-port 6379 --names redis-slave-674d68586-jnf7f --namespace default --kubeconfig config
Copied!
如果执行失败,会返回详细的错误信息;如果执行成功,会返回实验的 UID:
1
{"code":200,"success":true,"result":"127f1ee0afcd4798"}
Copied!
可通过以下命令查询实验状态:
1
blade query k8s create 127f1ee0afcd4798 --kubeconfig config
2
3
{"code":200,"success":true,"result":{"uid":"127f1ee0afcd4798","success":true,"error":"","statuses":[{"id":"b5a216dddeb3389f","uid":"4f1a28a1-fee6-11e9-8883-00163e0ad0b3","name":"chaosblade-tool-vv49t","state":"Success","kind":"pod","success":true,"nodeName":"cn-hangzhou.192.168.0.204"}]}}
Copied!
销毁实验:
1
blade destroy 127f1ee0afcd4798
Copied!

常见问题

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