[root@master-01 chaos-mesh]# bash install.sh Install Chaos Mesh chaos-mesh customresourcedefinition.apiextensions.k8s.io/iochaos.chaos-mesh.org created customresourcedefinition.apiextensions.k8s.io/kernelchaos.chaos-mesh.org created customresourcedefinition.apiextensions.k8s.io/networkchaos.chaos-mesh.org created customresourcedefinition.apiextensions.k8s.io/podchaos.chaos-mesh.org created customresourcedefinition.apiextensions.k8s.io/podiochaos.chaos-mesh.org created customresourcedefinition.apiextensions.k8s.io/podnetworkchaos.chaos-mesh.org created customresourcedefinition.apiextensions.k8s.io/stresschaos.chaos-mesh.org created customresourcedefinition.apiextensions.k8s.io/timechaos.chaos-mesh.org created namespace/chaos-testing created serviceaccount/chaos-controller-manager created secret/chaos-mesh-webhook-certs created clusterrole.rbac.authorization.k8s.io/chaos-mesh:chaos-controller-manager-target-namespace created clusterrole.rbac.authorization.k8s.io/chaos-mesh:chaos-controller-manager-cluster-level created clusterrolebinding.rbac.authorization.k8s.io/chaos-mesh:chaos-controller-manager-cluster-level created clusterrolebinding.rbac.authorization.k8s.io/chaos-mesh:chaos-controller-manager-target-namespace created role.rbac.authorization.k8s.io/chaos-mesh:chaos-controller-manager-control-plane created rolebinding.rbac.authorization.k8s.io/chaos-mesh:chaos-controller-manager-control-plane created service/chaos-dashboard created service/chaos-mesh-controller-manager created daemonset.apps/chaos-daemon created deployment.apps/chaos-dashboard created deployment.apps/chaos-controller-manager created mutatingwebhookconfiguration.admissionregistration.k8s.io/chaos-mesh-mutation created validatingwebhookconfiguration.admissionregistration.k8s.io/chaos-mesh-validation created Waiting for pod running chaos-controller-manager-86c96f985f-2dc5m 0/1 ContainerCreating 0 11s Waiting for pod running Waiting for pod running Chaos Mesh chaos-mesh is installed successfully [root@master-01 chaos-mesh]# kubectl get pod -n chaos-testing NAME READY STATUS RESTARTS AGE chaos-controller-manager-86c96f985f-2dc5m 1/1 Running 0 113s chaos-daemon-4j2rx 1/1 Running 0 113s chaos-dashboard-5d8dff7df9-zmfs9 1/1 Running 0 113s [root@master-01 chaos-mesh]# kubectl get svc -n chaos-testing NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE chaos-dashboard NodePort 10.101.249.22 <none> 2333:31679/TCP 3m17s chaos-mesh-controller-manager ClusterIP 10.109.203.98 <none> 10081/TCP,10080/TCP,443/TCP 3m16s
[root@master-01 chaos-mesh]# helm search repo chaos-mesh NAME CHART VERSION APP VERSION DESCRIPTION chaos-mesh/chaos-mesh v0.4.0 v1.1.0 Chaos Mesh® is a cloud-native Chaos Engineerin...
[root@master-01 dns]# kubectl get pod -n chaos-testing NAME READY STATUS RESTARTS AGE chaos-controller-manager-6c4c5b56d4-czbhb 1/1 Running 0 45m chaos-daemon-m7cg6 1/1 Running 0 47m chaos-dashboard-6f4c9d8dfc-tptp4 1/1 Running 0 45m chaos-dns-server-849c69bc7d-4tsqg 1/1 Running 0 47m
简单测试
模拟pod故障
这里我们定义一个测试场景,在这个场景中,我们将为一个命名空间中的 Pod 配置 Chaos,它将被安排每1分钟杀死一个 Pod。本例中 App 没有标签选择器,所以在多副本部署的情况下,它可以杀死任何 Pod。我们可以在配置中拥有不同的作用域。
首先让我们克隆我们的示例仓库来获得 YAML 资源清单文件。
1 2 3 4 5 6
git clone https://github.com/ronakbanka/chaos-mesh-examples.git cd chaos-mesh-examples/pod-chaos [root@master-01 pod-chaos]# kubectl apply -f pod-namespace-selector.yml namespace/appns created deployment.apps/nginx created podchaos.chaos-mesh.org/pod-kill-example created
https://github.com/chaos-mesh/web-show.git [root@master-01 chaos-mesh]# git clone https://github.com/chaos-mesh/web-show.git 正克隆到 'web-show'... remote: Enumerating objects: 176, done. remote: Counting objects: 100% (176/176), done. remote: Compressing objects: 100% (118/118), done. 接收对象中: 100% (176/176), 405.05 KiB | 29.00 KiB/s, done. remote: Total 176 (delta 68), reused 151 (delta 47), pack-reused 0 处理 delta 中: 100% (68/68), done. [root@master-01 chaos-mesh]# cd web-show/ [root@master-01 web-show]# ls chaos deploy deploy.sh Dockerfile go.mod go.sum LICENSE main.go Makefile pkg README.md server web [root@master-01 web-show]# cd deploy/ [root@master-01 deploy]# ls deployment.yaml service.yaml [root@master-01 deploy]# ls ../chaos/ network-delay.yaml [root@master-01 deploy]# kubectl apply -f ./ deployment.apps/web-show created service/web-show created
然后编辑network-delay.yaml修改如下并apply
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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"