混沌测试平台 Chaos Mesh

混沌测试平台 Chaos Mesh

Chaos Mesh 是PingCap团队研发的一款用于测试kubernetes环境的工具。通过人为地在集群中注入故障来检测集群对故障的处理以及恢复能力。更详细信息可以查看这篇文章。混沌测试与针对某个应用测试的区别为:前者更倾向于在现有大规模集群中进行测试,影响因素可能来自集群中的方方面面;而后者更专注于对应用本身功能的测试。

GitHub上目前有两款star数高的混沌项目,litmuschaos-mesh,这两款的功能和场景都基本类似,前者目前提供的混沌注入功能比较多,但后者提供了简单的UI界面。两者都可以扩展自定义的场景。

下面以chaos-mesh为例简单看下其提供的功能。

minikube下的安装可以参见官方文档

在安装完后可以看到如下pod,一个controller,一个daemonset以及一个dashboard

# kubectl get pod -n chaos-testing
NAME                                      READY   STATUS    RESTARTS   AGE
chaos-controller-manager-fd568948-hl8wv   1/1     Running   0          59m
chaos-daemon-5zfzh                        1/1     Running   0          59m
chaos-dashboard-6d8466f445-2k8sl          1/1     Running   0          59m

dashboard示意图如下:

目前支持的混沌测试如下:

# kubectl get crd
NAME                          CREATED AT
iochaos.chaos-mesh.org        2020-07-29T08:18:55Z
kernelchaos.chaos-mesh.org    2020-07-29T08:18:55Z
networkchaos.chaos-mesh.org   2020-07-29T08:18:55Z
podchaos.chaos-mesh.org       2020-07-29T08:18:55Z
stresschaos.chaos-mesh.org    2020-07-29T08:18:55Z
timechaos.chaos-mesh.org      2020-07-29T08:18:55Z

其原理也比较简单,类似istio的网格方式,通过admission webhook给pod注入sidecar,然后通过该sidecar进行故障注入。其支持的webhook如下:

# kubectl get MutatingWebhookConfiguration chaos-mesh-sidecar-injector
NAME                          WEBHOOKS   AGE
chaos-mesh-sidecar-injector   7          61m
# kubectl get ValidatingWebhookConfiguration
NAME                    WEBHOOKS   AGE
chaos-mesh-validation   6          61m

使用起来也比较简单,以pod-failure类型的故障为例,主要创建一个PodChaos的crd对象,并将selector设置为pod的标签即可。

apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata:
  name: pod-failure-example
  namespace: chaos-testing
spec:
  action: pod-failure # the specific chaos action to inject; supported actions: pod-kill/pod-failure
  mode: one # the mode to run chaos action; supported modes are one/all/fixed/fixed-percent/random-max-percent
  duration: "60s" # duration for the injected chaos experiment
  selector: # pods where to inject chaos actions
    labelSelectors:
      "app.kubernetes.io/component": "tikv" # the label of the pod for chaos injection
  scheduler: # scheduler rules for the running time of the chaos experiments about pods.
    cron: "@every 5m"

总体来说,混沌测试更像是集成验证的一部分,通过在现有运行环境中注入故障来发现系统或应用的兼容性问题,故障恢复能力问题等。典型的一个场景可以参考PingCap官方提供的Chaos Mesh 能做些什么?

猜你喜欢

转载自www.cnblogs.com/charlieroro/p/13398404.html