当前位置:网站首页>【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
2022-07-07 06:20:00 【仙女肖消乐】
根据标签删除POD
目标:在 chaosblade 命名空间中,对 redis-master-68857cd57c-dzbs9 Pod 的本地 6379
端口添加 3000 毫秒访问延迟,延迟时间上下浮动 1000 毫秒。
delay_pod_network_by_names.yaml 内容:
apiVersion: chaosblade.io/v1alpha1
kind: ChaosBlade
metadata:
name: delay-pod-network-by-names
spec:
experiments:
- scope: pod
target: network
action: delay
desc: "delay pod network by names"
matchers:
- name: names
value:
- "redis-master-68857cd57c-dzbs9"
- name: namespace
value:
- "chaosblade"
- name: local-port
value: ["6379"]
- name: interface
value: ["eth0"]
- name: time
value: ["3000"]
- name: offset
value: ["1000"]
获取 Pod 名称
$ kubectl get pod -l app=redis,role=master -o jsonpath={
.items..metadata.name}
修改 delay_pod_network_by_names.yaml 中的 name 字段的值。
开始模拟:
$ kubectl apply -f delay_pod_network_by_names.yaml
查看模拟配置详情
kubectl get blade delay-pod-network-by-names -o yaml
观察结果:可以看到访问实验 pod 6379 端口的延迟为 3s 左右,结果符合预期。
# 获取实验 pod ip
$ kubectl get pod -l app=redis,role=master -o jsonpath={
.items..status.podIP}
10.42.69.44
# 进入观测 pod
$ kubectl exec -it redis-slave-6dd975d4c8-2zrkb bash
# 在 pod 中安装 telnet
$ apt-get update && apt-get install -y telnet
# 测试时间
$ time echo "" | telnet 10.42.69.44 6379
Trying 10.42.69.44...
Connected to 10.42.69.44.
Escape character is '^]'.
Connection closed by foreign host.
real 0m3.790s
user 0m0.007s
sys 0m0.001s
停止实验
执行命令:kubectl delete -f delay_pod_network_by_names.yaml
或者直接删除 blade 资源:kubectl delete blade delay-pod-network-by-names
Pod 域名访问异常场景
目标:Pod 内访问指定域名异常。
获取 pod 名称内容同上。
dns_pod_network_by_names.yaml 内容:
apiVersion: chaosblade.io/v1alpha1
kind: ChaosBlade
metadata:
name: dns-pod-network-by-names
spec:
experiments:
- scope: pod
target: network
action: dns
desc: "dns pod network by names"
matchers:
- name: names
value:
- "redis-slave-6dd975d4c8-lm8jz"
- name: namespace
value:
- "chaosblade"
- name: domain
value: ["www.baidu.com"]
- name: ip
value: ["10.0.0.1"]
执行命令
$ kubectl apply -f dns_pod_network_by_names.yaml
查看实验状态
执行 kubectl get blade dns-pod-network-by-names -o json 命令,查看实验状态。
观测结果
# 进入实验 pod
$ kubectl exec -it redis-slave-6dd975d4c8-lm8jz bash
# Ping www.baidu.com
$ ping www.baidu.com
# 无响应
可以看到访问指定域名 www.baidu.com 异常,结果符合预期。
停止实验
执行命令:kubectl delete -f dns_pod_network_by_names.yaml
或者直接删除 blade 资源:kubectl delete blade dns-pod-network-by-names
Pod 文件系统 I/O 故障场景
目标:给 kubernetes 的 pod 注入文件系统I/O故障。
注意:此场景需要激活 --webhook-enable 参数,如需使用此功能,请在 chaosblade-operator 参数中添加
–webhook-enable,或者在安装时指定:例如 helm 安装时添加 --set webhook.enable=true 指定。
前提条件
集群中部署了 chaosblade-admission-webhook•需要注入故障的 volume 设置
mountPropagation 为 HostToContainer•pod上面添加了如下annotations:chaosblade/inject-volume: “data” //需要注入故障的volume name
chaosblade/inject-volume-subpath: “conf” //volume 挂载的子目录
部署测试 pod
chaosblade webhook 会根据 pod 的 annotation,注入 fuse 的 sidecar 容器:
1.chaosblade/inject-volume 指明需要注入故障的 volume name,比如例子中的 data。2.chaosblade/inject-volume-subpath 指明 volume
挂载路径的子目录。上面的例子中,volume 的挂载路径是 /data,子目录是 conf,则在 pod 内,注入I/O异常的目录是
/data/conf。3.指定需要注入故障的 volume 需要指定
mountPropagation:HostToContainer,这个字段的含义可以参考官方文档 Volumes[3]。
# 部署测试 pod
$ kubectl apply -f io-test-pod.yaml
# 查看 sidecar 是否注入成功
$ kubectl get pod test-7c9fc6fd88-7lx6b -n chaosblade
NAME READY STATUS RESTARTS AGE
test-7c9fc6fd88-7lx6b 2/2 Running 0 4m8s
pod_io.yaml 内容:
apiVersion: chaosblade.io/v1alpha1
kind: ChaosBlade
metadata:
name: inject-pod-by-labels
spec:
experiments:
- scope: pod
target: pod
action: IO
desc: "Pod IO Exception by labels"
matchers:
- name: labels
value:
- "app=test"
- name: namespace
value:
- "chaosblade"
- name: method
value:
- "read"
- name: delay
value:
- "1000"
- name: path
value:
- ""
- name: percent
value:
- "60"
- name: errno
value:
- "28"
执行命令
$ kubectl apply -f pod_io.yaml
查看实验状态
执行 kubectl get blade inject-pod-by-labels -o json 命令,查看实验状态
观测结果
# 进入实验 pod
$ kubectl exec -it test-7c9fc6fd88-7lx6b bash
# 在 pod 内读取指定目录中的文件,如果没有可以新建一个
$ time cat /data/conf/test.yaml
cat: read error: No space left on device
real 0m3.007s
user 0m0.002s
sys 0m0.002s
# 因为有重试,显示有 3s 的延迟
# 因为设置了 60% 的异常,所有还是有成功的情况
$ time cat /data/conf/test.yaml
123
real 0m0.004s
user 0m0.002s
sys 0m0.000s
文件读取异常,结果符合预期。
在本例中,我们对 read 操作注入两种异常,异常率为百分之60:
对 read 操作增加 1s 的延迟。•对 read 操作返回错误 28。
这里只是做了一种类型的实验,更多的实验类型详见官方文档[4]。
停止实验
执行命令:kubectl delete -f pod_io.yaml
或者直接删除 blade 资源:kubectl delete blade inject-pod-by-labels
删除测试 pod:kubectl delete -f io-test-pod.yaml
边栏推荐
- 数据分片介绍
- Frequently Asked Coding Problems
- QT charts use (rewrite qchartview to realize some custom functions)
- 模拟卷Leetcode【普通】1705. 吃苹果的最大数目
- ncs成都新电面试经验
- oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
- leetcode134. gas station
- Mock. JS usage details
- Find the original code, inverse code and complement of signed numbers [C language]
- 調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
猜你喜欢
随机推荐
How to integrate app linking services in harmonyos applications
Uniapp wechat applet monitoring network
Speaking of a software entrepreneurship project, is there anyone willing to invest?
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
PPT模板、素材下载网站(纯干货,建议收藏)
[Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
Why choose cloud native database
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - package based on thinkphp5 - detailed guidance of the author - July 6, 2022 - Novice
Category of IP address
Redis fault handling "can't save in background: fork: cannot allocate memory“
What are the advantages of commas in conditional statements- What is the advantage of commas in a conditional statement?
Skills that testers must know: Selenium's three waiting ways are interpreted clearly
LeetCode 715. Range 模块
南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
LeetCode 715. Range module
idea里使用module项目的一个bug
How to realize sliding operation component in fast application
systemd