In Kubernetes, Datadog tracers can send data to the Datadog Agent in three ways: Unix Domain Socket (UDS), host IP, or a Kubernetes service. Each option ensures that when an application pod sends APM data, the data arrives at a Datadog Agent pod on the same node. This strategy is meant to properly balance traffic and ensure the correct tagging of your data. Datadog recommends that you use UDS to send data.
However, if the hostPath volumes required for UDS (and the hostPort ports required for using host IP) are not available, you can use a Kubernetes service as an alternative option.
This guide describes how to configure using a Kubernetes service to send data to the Datadog Agent.
In Kubernetes 1.22, the Internal Traffic Policy feature provides the option to set the configuration internalTrafficPolicy: Local on a service. When set, traffic from an application pod is directed to the service’s downstream pod on the same node.
If you installed the Datadog Agent by using the Datadog Helm chart or Datadog Operator on clusters with Kubernetes v1.22.0+, a service for the Agent with internalTrafficPolicy: Local is automatically created for you. You additionally need to enable the APM port option for your Agent with the below configuration.
The Cluster Agent’s Admission Controller can inject the configuration for APM connectivity into your containers. The options are hostip, socket, or service. Choose the service mode to have the Admission Controller add the DD_AGENT_HOST environment variable for the DNS name of the service.
Note: In mixed node (Linux/Windows) environments, the Cluster Agent and its Admission Controller are relative to the Linux deployment. This may inject the wrong environment variables for the service connectivity in the Windows pods.
For manual configuration, set the environment variable DD_AGENT_HOST within your pod manifest, with a value of <SERVICE_NAME>.<SERVICE_NAMESPACE>.svc.cluster.local.