appdynamics/cluster-agent-operatorKubernetes 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 实例。
部署 CRD:
bashkubectl apply -f [***]
部署 Operator 控制器:
bashkubectl apply -f [***]
验证部署:
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
添加 Helm 仓库:
bashhelm repo add 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 版本
ClusterAgent CRD 包含以下核心字段(完整定义见 CRD 文档):
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)。创建 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
| 参数路径 | 类型 | 默认值 | 说明 |
|---|---|---|---|
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 |
完整参数说明见 CRD 文档,核心参数已在 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: max***: 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> 查看事件。manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务