
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
This small project written using https://go.dev implements the ideas of the https://netflix.github.io/chaosmonkey/ natively for https://kubernetes.io clusters.
For this small project I have decided not to use the official https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/, mainly because I wanted to familiarize with the core concepts of CRDs and Watchers with Golang before adventuring further. In the future I might want to migrate to using the Operator Framework.
The architecture of the Chaos Monkey is fairly simple and all fits in a single Pod. As you can imagine, we rely heavily on https://kubernetes.io/docs/reference/using-api/api-concepts/ to react based on what happens inside the cluster.
Three main components are part of the current architecture.
The code for the NamespaceWatcher can be found here.
Its role is to constantly monitor the changes in the Namespaces of the cluster, and start
the CRD Watchers for those Namespaces. We start the watch by passing ResourceVersion: ""
to the Kubernetes API, which means that the first events we receive are synthetic events
(ADD) to help us rebuild the current state of the cluster. After that, we react to both
the ADDED and the DELETED events accordingly.
Basically, it spawns a new https://go.dev/tour/concurrency/1 with a CRD Watcher everytime a new namespace is detected and it stops the corresponding goroutine when a namespace is deleted.
We make use of a https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/ in order to trigger the Chaos Monkey. The CRD is defined using the OpenAPI specification, which you can find here.
Following the schema, this is a valid definition of a CRD which can be injected inside of a namespace:
yamlapiVersion: cm.massix.github.io/v1alpha1 kind: ChaosMonkeyConfiguration metadata: name: chaosmonkey-nginx namespace: target spec: enabled: true minReplicas: 0 maxReplicas: 9 timeout: 10s deploymentName: nginx
The CRD is namespaced, meaning that it must reside inside a Namespace and cannot be created at cluster-level.
The CRD Watcher, similarly to the namespace one, reacts to the
ADDED and DELETED events accordingly, creating and stopping goroutines, but it also
reacts to the MODIFIED event, making it possible to modify a configuration while the
Monkey is running.
This is where the fun begins, the Deployment Watcher is responsible of creating the
Chaos inside the cluster. The watcher is associated to a specific deployment (see the
example CRD above), and at regular intervals, specified by the spec.timeout field
of the CRD, it scales up or down the deployment. This allows us to test both the case
where there are less replicas than we need, but also the case when there are more
replicas than the cluster can probably handle.
All the fields in the CRDs are mandatory and must be set. There are some simple validations done by Kubernetes itself, which are embedded in the OpenAPI Schema and some other validations are done in the code.
In order to be able to deploy the ChaosMonkey inside a Kubernetes cluster you must first create a https://kubernetes.io/docs/concepts/security/service-accounts/, followed by a https://kubernetes.io/docs/reference/access-authn-authz/rbac/ and ***d the two together with a https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role***ding-and-clusterrole***ding.
After that you need to inject the CRD contained in this repository:
kubectl apply -f ./crds/chaosmonkey-configuration.yaml
Then you can create a classic https://kubernetes.io/docs/concepts/workloads/controllers/deployment/, just remember to use your newly created ServiceAccount.
Following is an example of the manifests you should create for the cluster:
yamlkind: Namespace apiVersion: v1 metadata: name: chaosmonkey --- kind: ServiceAccount apiVersion: v1 metadata: name: chaosmonkey namespace: chaosmonkey --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: chaosmonkey rules: - apiGroups: ["*"] resources: ["namespaces"] verbs: ["watch"] - apiGroups: ["*"] resources: ["deployments"] verbs: ["patch", "get", "scale", "update"] - apiGroups: ["*"] resources: ["chaosmonkeyconfigurations"] verbs: ["list", "patch", "watch"] - apiGroups: ["apps"] resources: ["deployments/scale"] verbs: ["update"] - apiGroups: ["*"] resources: ["events"] verbs: ["create", "patch"] --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: chaosmonkey-binding subjects: - kind: ServiceAccount name: chaosmonkey namespace: chaosmonkey roleRef: kind: ClusterRole apiGroup: rbac.authorization.k8s.io name: chaosmonkey --- kind: Deployment apiGroup: apps/v1 metadata: name: chaosmonkey namespace: chaosmonkey spec: # some fields omitted for clarity template: spec: serviceAccountName: chaosmonkey
The only configuration possible for the ChaosMonkey is setting the minimum log level,
this is done by setting the environment variable CHAOSMONKEY_LOGLEVEL to one of the
following values: trace, debug, info, warn, error, critical or panic.
The value is not case-sensitive.
Invalid or e***y values will make ChaosMonkey default to the info level.
All contributions are welcome, of course. Feel free to open an issue or submit a pull request. If you want to develop and test locally, you need to install:
The reason why you need so many tools, is because there is an embedded terraform file which spawns a Kubernetes cluster in your local machine using Kind, injects the CRD, builds the image and gives you a working environment to test your development. There are some unit tests included, but since all the interactions with Kubernetes are mocked, we cannot be sure that everything will work once deployed.
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务