混沌工程之ChaosMesh使用之模拟POD网络延迟

x33g5p2x  于2021-11-01 转载在 其他  
字(1.2k)|赞(0)|评价(0)|浏览(292)

前言

在这一篇中我们来看一下如何模拟 POD 网络故障。

模拟 POD 网络延迟

目标

指定 pod 产生 10 ms延迟。

配置文件

apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
  name: web-show-network-delay
spec:
  action: delay # the specific chaos action to inject
  mode: one # the mode to run chaos action; supported modes are one/all/fixed/fixed-percent/random-max-percent
  selector: # pods where to inject chaos actions
    namespaces:
      - default
    labelSelectors:
      "app": "web-show"  # the label of the pod for chaos injection
  delay:
    latency: "10ms"
  duration: "30s" # duration for the injected chaos experiment
  scheduler: # scheduler rules for the running time of the chaos experiments about pods.
    cron: "@every 60s"

来看下这段配置,是指定 在 default 的命名空间中,使用 app=web-show 标签搜索 POD,配置网络延迟为 10 ms,持续 30 s时间,并且每 60s 执行一次。

执行

保存上面的配置到 yaml 文件中,执行 apply 命令:

[root@s5 ChaosMesh]# kubectl apply -f network-delay.yaml
networkchaos.chaos-mesh.org/web-show-network-delay created
[root@s5 ChaosMesh]#

验证

这里我们用 jmeter 脚本来验证,直接来查看 summary report。

混沌实验执行前:

混沌实验执行后:

从混沌试验执行前后的平均响应时间来看,响应时间确实增加了10ms左右。

恢复

[root@s5 ChaosMesh]# kubectl delete -f network-delay.yaml
networkchaos.chaos-mesh.org "web-show-network-delay" deleted

这个案例是直接使用yaml文件执行的,并没有从界面上配置。效果和从界面上配置是一样的。

像 chaoblade-operator 也是通过类似的方式实现的。

留个思考题给你

  • 这样实现的网络延迟的原理是什么?

相关文章

微信公众号

最新文章

更多