常见问题解答
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
如果尚未部署 Kubernetes 集群,能否使用 Chaos Mesh 创建混沌实验?
不能。但您可以使用 chaosd 在非 Kubernetes 环境中注入故障。
已成功部署 Chaos Mesh 并创建 PodChaos 实验,但创建 NetworkChaos/TimeChaos 实验仍失败,错误日志如下:
2020-06-18T02:49:15.160Z ERROR controllers.TimeChaos failed to apply chaos on all pods {"reconciler": "timechaos", "error": "rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing dial tcp xx.xx.xx.xx:xxxx: connect: connection refused\""}
这是因为 chaos-controller-manager 无法连接到 chaos-daemon。请先检查 Pod 网络及其策略。
若检查无误,可尝试使用 hostNetwork 参数解决此问题,方法如下:
默认的 Google Cloud 管理员账户无法创建混沌实验,如何解决?
默认 Google Cloud 管理员账户无法通过 AdmissionReview 校验。您需创建管理员角色并分配给账户,授予其创建混沌实验的权限。例如:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: role-cluster-manager-pdmas
rules:
- apiGroups: ['']
resources: ['pods', 'namespaces']
verbs: ['get', 'watch', 'list']
- apiGroups:
- chaos-mesh.org
resources: ['*']
verbs: ['get', 'list', 'watch', 'create', 'delete', 'patch', 'update']
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-manager-binding
namespace: chaos-mesh
subjects:
# Google Cloud user account
- kind: User
name: USER_ACCOUNT
roleRef:
kind: ClusterRole
name: role-cluster-manager-pdmas
apiGroup: rbac.authorization.k8s.io
上述 USER_ACCOUNT 应替换为您的 Google Cloud 用户邮箱。
Daemon 抛出类似 version 1.41 is too new. The maximum supported API version is 1.39 的错误
这表明 Docker daemon 支持的最高 API 版本为 1.39,但 chaos-daemon 客户端默认使用 1.41。可通过以下任一方案解决:
-
将 Docker 升级至新版
-
Helm 安装/升级时添加参数
--set chaosDaemon.env.DOCKER_API_VERSION=1.39
DNSChaos
在 OpenShift 中运行 DNSChaos 时遭遇授权问题导致中断
若错误信息类似如下:
Error creating: pods "chaos-dns-server-123aa56123-" is forbidden: unable to validate against any security context constraint: [spec.containers[0].securityContext.capabilities.add: Invalid value: "NET_BIND_SERVICE": capability may not be added]
请为 chaos-dns-server 添加 privileged 安全上下文约束(SCC)
oc adm policy add-scc-to-user privileged -n chaos-mesh -z chaos-dns-server
安装
在 OpenShift 中安装 Chaos Mesh 时遭遇授权问题导致中断
若错误信息类似如下:
Error creating: pods "chaos-daemon-" is forbidden: unable
to validate against any security context constraint: [spec.securityContext.hostNetwork:
Invalid value: true: Host network is not allowed to be used spec.securityContext.hostPID:
Invalid value: true: Host PID is not allowed to be used spec.securityContext.hostIPC:
Invalid value: true: Host IPC is not allowed to be used securityContext.runAsUser:
Invalid value: "hostPath": hostPath volumes are not allowed to be used spec.containers[0].securityContext.volumes[1]:
Invalid value: true: Host network is not allowed to be used spec.containers[0].securityContext.containers[0].hostPort:
Invalid value: 31767: Host ports are not allowed to be used spec.containers[0].securityContext.hostPID:
Invalid value: true: Host PID is not allowed to be used spec.containers[0].securityContext.hostIPC:
......]
请为 default 添加 privileged scc
oc adm policy add-scc-to-user privileged -n chaos-mesh -z chaos-daemon
安装 Chaos Mesh 失败并提示:no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1"
此问题出现在 Kubernetes v1.15 或更低版本。Chaos Mesh 默认使用 apiextensions.k8s.io/v1(该 API 于 2019-09-19 在 Kubernetes v1.16 引入)
在低于 v1.16 的 Kubernetes 上安装时,请按以下流程操作:
-
通过
https://mirrors.chaos-mesh.org/<chaos-mesh-version>/crd-v1beta1.yaml手动创建 CRD -
添加
--validate=false参数(否则可能因 CRD 破坏性变更导致兼容问题)。例如:kubectl create -f https://mirrors.chaos-mesh.org/v2.1.0/crd-v1beta1.yaml --validate=false -
使用 Helm 完成剩余安装步骤,并在
helm install命令后添加--skip-crds参数
建议参考 Kubernetes 版本偏差策略升级集群
Chaosd
执行失败并报错:attempt to write a readonly database
在命令模式或服务模式下运行 chaosd 时,若当前用户对 chaosd 使用的 SQLite 数据库文件缺乏写入权限,则会出现此错误。默认情况下,数据库文件位于 chaosd 安装目录中:/usr/local/chaosd-v$VERSION-$OS-$ARCH/chaosd.db(例如 /usr/local/chaosd-v1.4.0-linux-amd64/chaosd.db)。
解决方法:授予数据库文件写入权限:
# Replace the path with your actual chaosd installation directory
sudo chmod 666 /usr/local/chaosd-v*/chaosd.db
# Also ensure the directory is writable
sudo chmod 775 /usr/local/chaosd-v*/
也可选择以适当权限运行 chaosd,或将数据库文件所有权更改为当前用户。
涉及 tc 和 iptables 的网络混沌实验需要 sudo 权限
创建使用 tc(流量控制)或 iptables 的网络混沌实验时,必须使用 sudo 或 root 权限执行 chaosd 命令。若无适当权限,混沌攻击将无法生效且恢复操作也会失败。
需要 sudo 的网络混沌示例:
-
网络延迟、丢包、重复或损坏
-
网络带宽限制
-
网络分区
运行这些实验的正确方式:
# Command mode
sudo chaosd attack network delay --device eth0 --latency 100ms
# Service mode - start the service with sudo
sudo chaosd server
若未使用 sudo,修改网络配置时可能出现 "permission denied" 或 "operation not permitted" 等错误。