Datadog Agent Host‑Path Docker Socket vs Kubernetes Cluster Agent Integration in Production
0 reputation · 24 Dec 2020, 03:47 UTC
0 reputation · 24 Dec 2020, 03:47 UTC
The goal is to maintain continuous collection of container metrics and logs from a Datadog Agent when moving from a local development cluster to a production Kubernetes environment that enforces strict security policies.
In local setups the Agent runs with privileged=true and mounts the node’s /var/run/docker.sock via a hostPath, allowing it to observe Docker events and read pod annotations such as ad.datadoghq.com/.logs for autodiscovery.
Production clusters frequently prohibit privileged containers and hostPath mounts through PodSecurityPolicies or OPA/Gatekeeper, and admission controllers may strip or alter those annotations, causing the Agent to lose visibility without clear error messages.
An unresolved decision is whether to replace the host‑socket approach with the Datadog Cluster Agent and Node Agent, which operate without privileged mode but require additional RBAC configuration and may not fully replicate the original discovery mechanism for existing custom checks.
Does removing privileged mode and hostPath mounts prevent the Agent from discovering Docker containers? Can the Cluster Agent and Node Agent fully replace host‑socket based autodiscovery for logs and metrics? What RBAC permissions are needed for the Node Agent to access pod annotations without interference from admission controllers?
33775 reputation · 24 Dec 2020, 10:19 UTC
Removing privileged mode and the /var/run/docker.sock hostPath mount does not prevent the Agent from discovering containers — provided you switch discovery from the Docker API to the Kubernetes API. That is exactly what the Cluster Agent + Node Agent architecture does. It fully covers annotation-based autodiscovery for logs and metrics, with one caveat: custom checks that read low-level Docker engine internals (not exposed via the Kubelet) will lose data and must be rewritten or dropped.
Confirmed behavior: the Docker socket listener is the only thing that requires the socket mount. Without it, the Agent's Docker-based autodiscovery and docker.* metrics stop. Kubernetes autodiscovery instead reads pod annotations (ad.datadoghq.com/) through the API server, and container metrics come from the Kubelet — neither needs privilege or hostPath.
Likely explanation for your silent visibility loss: the admission controller stripping or rejecting the ad.datadoghq.com/* annotations is the more probable culprit than the Agent itself. The Agent fails quietly when annotations never reach the API server, which matches your symptom of "loses visibility without clear error messages."
The Node Agent's ServiceAccount needs read access to pod metadata. The standard ClusterRole includes:
rules:
- apiGroups: [""]
resources: ["pods", "nodes", "namespaces", "endpoints", "services"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources: ["deployments", "replicasets", "daemonsets", "statefulsets"]
verbs: ["get", "list", "watch"]The Cluster Agent additionally needs permissions for the resources it aggregates (e.g., events, and externalmetrics if you use the metrics adapter). Use the manifests from the Datadog Helm chart as the baseline rather than hand-rolling RBAC.
RBAC cannot help if Gatekeeper mutates or strips annotations before pods are created — the Agent reads what the API server stored. You must whitelist the ad.datadoghq.com/ annotation prefix in your OPA/Gatekeeper policy (and any annotation-size or annotation-allowlist rules). Verify with:
kubectl get pod <name> -o jsonpath='{.metadata.annotations}'If the ad.datadoghq.com/* keys are absent there, the problem is policy, not the Agent.
kubectl exec <node-agent> -- agent status — confirm the Kubernetes listener and config provider are active and autodiscovery templates are resolved.Exact RBAC resources and Helm values vary by Agent version (7.x assumed here); verify against the chart version you deploy. If any custom check depends on Docker engine stats unavailable through the Kubelet, identify it before cutover — that is the one gap the Cluster Agent pattern does not close.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.