什么是 Argo CD?
Argo CD 是一个开源的 CD(Continuous Delivery)工具,能够帮助您在 Kubernetes 环境中进行持续交付。Argo CD 的主要功能是将配置文件同步到 Kubernetes 集群中并确保应用程序正确运行。Argo CD 可以自动检测应用程序的变化并自动同步应用程序配置文件。此外,它还支持各种 CI / CD工具(如 Jenkins,GitLab 等)和 Kubernetes 平台的其它工具集成,从而实现全生命周期的自动化。Argo CD还提供了一个可视化的控制台,并且能够通过 API 和 CLI 进行操作、管理。
Argo CD 可观测性体系
Argo CD 通过 Prometheus 协议暴露指标,通过这些指标可用于监控 Argo CD 服务状态和应用状态。Argo CD 主要暴露三类指标:
- Application Controller Metrics:Argo CD 应用相关指标,例如应用数、Argo CD 状态等。
- API Server Metrics:Argo CD API 请求指标,例如请求数、响应码等。
- Repo Server Metrics:Repo Server 相关指标,例如 Git 请求数、Git 响应时间等。
Argo CD 指标详情可参考官方文档: ArgoCD - 观测云文档
Argo CD 日志均通过 Kubernetes 控制台输出,日志基本格式如下:
time="2023-06-15T15:00:50Z" level=info msg="Generating self-signed TLS certificate for this session"
Argo CD 2.4 #7539 加入了 OpenTelemetry 协议的支持,可通过暴露的 otlp 地址来获取链路数据。
Argo CD 可观测性接入方案
准备工作
登录观测云控制台,选择「集成」-「DataKit」-「Kubernetes」或「Kubernetes(Helm)」,按照指引安装 DataKit 采集器,并打开 Opentelemetry 采集器:
修改 ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: datakit-conf
namespace: datakit
data:
#### opentelemetry
opentelemetry.conf: |-
[[inputs.opentelemetry]]
[inputs.opentelemetry.http]
enable = true
http_status_ok = 200
[inputs.opentelemetry.grpc]
trace_enable = true
metric_enable = true
addr = "0.0.0.0:4317"
挂载配置至容器中 ,添加 env 配置,ENV_INPUT_CONTAINER_ENABLE_AUTO_DISCOVERY_OF_PROMETHEUS_SERVICE_MONITORS,打开 Service Monitor 自动发现,用于收集 Argo CD 指标。
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app: daemonset-datakit
name: datakit
namespace: datakit
spec:
...
template:
...
spec:
...
containers:
- env:
...
- name: ENV_INPUT_CONTAINER_ENABLE_AUTO_DISCOVERY_OF_PROMETHEUS_SERVICE_MONITORS
value: "true"
...
volumeMounts:
...
- mountPath: /usr/local/datakit/conf.d/opentelemetry/opentelemetry.conf
name: datakit-conf
subPath: opentelemetry.conf
...
修改 datakit.yaml,Service 打开 4317 端口。
apiVersion: v1
kind: Service
metadata:
name: datakit-service
namespace: datakit
spec:
selector:
app: daemonset-datakit
ports:
- name: datakit
protocol: TCP
port: 9529
targetPort: 9529
- name: opentelemetry
protocol: TCP
port: 4317
targetPort: 4317
指标
利用 Prometheus-Operator CRD 方式采集 Argo CD 指标,配置步骤如下:
1)安装 Prometheus-Operator
git clone https://github.com/coreos/prometheus-operator.git
cd prometheus-operator
kubectl create -f bundle.yaml
kubectl get pod -n default
2)创建 ServiceMonitor
- argocd-metrics.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: argocd-metrics
labels:
release: prometheus-operator
namespace: argocd
spec:
selector:
matchLabels:
app.kubernetes.io/name: argocd-metrics
endpoints:
- port: metrics
- argocd-server-metrics.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: argocd-server-metrics
labels:
release: prometheus-operator
namespace: argocd
spec:
selector:
matchLabels:
app.kubernetes.io/name: argocd-server-metrics
endpoints:
- port: metrics
- argocd-repo-server.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: argocd-repo-server-metrics
labels:
release: prometheus-operator
namespace: argocd
spec:
selector:
matchLabels:
app.kubernetes.io/name: argocd-repo-server
endpoints:
- port: metrics
- argocd-applicationset-controller.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: argocd-applicationset-controller-metrics
labels:
release: prometheus-operator
namespace: argocd
spec:
selector:
matchLabels:
app.kubernetes.io/name: argocd-applicationset-controller
endpoints:
- port: metrics
kubectl apply -f argocd-metrics.yaml
kubectl apply -f argocd-server-metrics.yaml
kubectl apply -f argocd-repo-server.yaml
kubectl apply -f argocd-applicationset-controller.yaml
kubectl get ServiceMonitor -n argocd
日志
安装 DataKit 采集器之后,默认会采集 Argo CD Pod 输出的日志,无须其他配置。
链路
修改 Argo CD 的 ConfigMap argocd-cmd-params-cm,加入 otlp.address 地址,即可获取 Argo CD 的链路。
- argocd-cmd-params-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/name: argocd-cmd-params-cm
app.kubernetes.io/part-of: argocd
name: argocd-cmd-params-cm
namespace: argocd
data:
otlp.address: datakit-service.datakit:4317
kubectl apply -f argocd-cmd-params-cm.yaml
Argo CD 可观测效果展示