如果你使用 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 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
Kubernetes Cluster Agent Operator 是一个基于 Kubernetes Operator 模式的管理组件,用于自动化集群级代理(Cluster Agent)的生命周期管理。该 Operator 通过自定义资源定义(CRD)和控制器逻辑,实现 Cluster Agent 的部署、配置更新、版本升级、故障自愈及监控集成等功能,旨在简化大规模 Kubernetes 集群中 Cluster Agent 的运维复杂度,确保代理组件的高可用性和配置一致性。
提供 ClusterAgent 自定义资源,支持通过 YAML 声明式配置 Agent 的部署参数(如镜像版本、资源限制、副本数等)。
ClusterAgent CR 规范自动创建 Agent 的 Deployment、Service 等资源。image.tag 字段触发滚动升级,内置版本兼容性检查,失败时可自动回滚。autoScaling 特性)。通过 Kubernetes Cluster API 或联邦集群(Federation)集成,支持跨集群管理 Cluster Agent 实例。
4.2.1 通过 kubectl 部署
部署 CRD:
bashkubectl apply -f https://raw.githubusercontent.com/example/cluster-agent-operator/main/config/crd/bases/agent.example.com_clusteragents.yaml
部署 Operator 控制器:
bashkubectl apply -f https://raw.githubusercontent.com/example/cluster-agent-operator/main/config/manager/manager.yaml
验证部署:
bash# 检查 Operator Pod 状态(默认部署在 cluster-agent-operator 命名空间) kubectl get pods -n cluster-agent-operator # 输出示例:NAME READY STATUS RESTARTS AGE # cluster-agent-operator-controller-manager-xxxx 2/2 Running 0 10s
4.2.2 通过 Helm Chart 部署
添加 Helm 仓库:
bashhelm repo add cluster-agent-operator https://example.github.io/cluster-agent-operator helm repo update
安装 Chart:
bashhelm install cluster-agent-operator cluster-agent-operator/cluster-agent-operator \ --namespace cluster-agent-operator \ --create-namespace \ --set image.tag=v1.2.0 # 指定 Operator 版本
4.3.1 CRD 定义说明
ClusterAgent CRD 包含以下核心字段(完整定义见 https://raw.githubusercontent.com/example/cluster-agent-operator/main/config/crd/bases/agent.example.com_clusteragents.yaml%EF%BC%89%EF%BC%9A
spec.image:Agent 镜像地址(如 example/cluster-agent:v2.3.0)。spec.replicas:Agent 副本数(默认 2,建议 ≥2 确保高可用)。spec.resources:资源限制(CPU/内存请求与限制)。spec.config:挂载的配置文件(支持 ConfigMap/Secret 引用)。spec.updateStrategy:升级策略(如 RollingUpdate 或 OnDelete)。4.3.2 CR 配置示例
创建 cluster-agent-example.yaml:
yamlapiVersion: agent.example.com/v1alpha1 kind: ClusterAgent metadata: name: cluster-agent-default namespace: kube-system # Agent 通常部署在系统命名空间 spec: image: repository: example/cluster-agent tag: v2.3.0 # Agent 版本 pullPolicy: IfNotPresent replicas: 3 # 3 副本确保高可用 resources: requests: cpu: 100m memory: 256Mi limits: cpu: 500m memory: 512Mi config: configMap: name: agent-config # 引用提前创建的 ConfigMap(需包含 agent.conf 等配置文件) updateStrategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 # 升级时允许 1 个副本不可用 monitoring: enabled: true # 启用 Prometheus 监控 serviceMonitor: enabled: true # 创建 ServiceMonitor 资源(需 Prometheus Operator)
应用 CR:
bashkubectl apply -f cluster-agent-example.yaml
4.3.3 核心配置参数说明
| 参数路径 | 类型 | 默认值 | 说明 |
|---|---|---|---|
spec.image.repository | string | example/cluster-agent | Agent 镜像仓库地址 |
spec.image.tag | string | latest | Agent 镜像标签(建议固定版本,避免自动更新) |
spec.replicas | int | 2 | Agent 副本数(生产环境建议 ≥2) |
spec.resources | object | {} | CPU/内存资源请求与限制 |
spec.config.configMap | object | null | 挂载的 ConfigMap 名称及键(配置文件) |
spec.updateStrategy.type | string | RollingUpdate | 升级策略(RollingUpdate/OnDelete) |
修改 ClusterAgent CR 即可触发配置更新,Operator 会自动执行滚动更新:
bash# 编辑 CR kubectl edit clusteragent cluster-agent-default -n kube-system # 修改 spec.image.tag 为 v2.4.0,保存退出后 Operator 会触发 Agent 升级
manager.yaml 或 Helm Chart 升级(需确保 CRD 兼容)。spec.image.tag 为上一稳定版本,Operator 会自动回滚。bashkubectl logs -n cluster-agent-operator deployment/cluster-agent-operator-controller-manager -c manager
cluster_agent_operator_reconcile_success_total:CR 调和成功次数cluster_agent_ready_replicas:Agent 就绪副本数cluster_agent_upgrade_failed_total:Agent 升级失败次数Operator 控制器支持通过环境变量调整运行参数(在 Deployment 的 env 字段配置):
| 环境变量名 | 说明 | 默认值 |
|---|---|---|
WATCH_NAMESPACE | 监听的命名空间(默认所有命名空间) | ""(全部) |
POD_NAME | Operator Pod 名称(自动注入) | metadata.name |
OPERATOR_NAME | Operator 名称 | cluster-agent-operator |
LOG_LEVEL | 日志级别(debug/info/warn/error) | info |
RECONCILE_DELAY | 调和重试延迟(秒) | 30 |
完整参数说明见 https://raw.githubusercontent.com/example/cluster-agent-operator/main/config/crd/bases/agent.example.com_clusteragents.yaml%EF%BC%8C%E6%A0%B8%E5%BF%83%E5%8F%82%E6%95%B0%E5%B7%B2%E5%9C%A8 4.3.3 节列出。
yaml# cluster-agent-operator-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: cluster-agent-operator-controller-manager namespace: cluster-agent-operator spec: replicas: 1 selector: matchLabels: control-plane: controller-manager template: metadata: labels: control-plane: controller-manager spec: containers: - name: manager image: example/cluster-agent-operator:v1.2.0 command: - /manager args: - --leader-elect env: - name: LOG_LEVEL value: info resources: limits: cpu: 500m memory: 512Mi requests: cpu: 100m memory: 256Mi
yamlapiVersion: agent.example.com/v1alpha1 kind: ClusterAgent metadata: name: cluster-agent-production namespace: kube-system spec: image: repository: example/cluster-agent tag: v2.4.0 pullPolicy: Always replicas: 3 resources: requests: cpu: 200m memory: 512Mi limits: cpu: 1000m memory: 1Gi config: configMap: name: agent-production-config items: - key: agent.conf path: agent.conf - key: cert.pem path: tls/cert.pem secret: name: agent-tls items: - key: key.pem path: tls/key.pem updateStrategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 monitoring: enabled: true serviceMonitor: enabled: true namespace: monitoring interval: 15s scrapeTimeout: 10s
ClusterAgent CR 的 status.conditions 字段,确认是否存在错误(如权限不足、镜像拉取失败)。Reconciliation failed 关键字定位问题。kubectl describe pod <agent-pod-name> 查看事件。您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

来自真实用户的反馈,见证轩辕镜像的优质服务