My scenario is that currently, I'm running my application as Daemon sets and want to integrate Datadog into my infrastructure. As my understanding is that Daemon sets purpose is to make sure one pod of each set is ran on each node.
Here I wanted to point my application at datadog agent so it will feed data into it. I've defined a Service
of Nodeport
type to expose the port of the agent. I provided the service name in my application definition and it works. For one node. What happens now when I will have more nodes? Will k8s be clever enough to route to the agent on the same nodes or there is a situation where a pod with my application might call the agent on a different node? Is this a correct setup?
My team ran it as a daemon set for the purposes of collecting node metrics, but only exposed it as a normal cluster IP service for the purposes of programmatically sending it data from other apps in the cluster. You don't need to expose it on a node port unless you need to access it from outside the cluster and don't have a service-aware load balancer like an ingress controller. (That would be quite a strange use case, so chances are you don't need to expose it on a node port.)
A better approach than using DaemonSets to run your application would be to use a Deployment so that you don't tie your application to the number of nodes in your cluster.
You can then deploy the datadog agent image as a DaemonSet with a set spec.template.spec.affinity
that selects nodes with a pod of your application running. This will make sure you have a datadog agent in every node where your application runs.
Another option is to deploy the datadog agent container in the same pod as your application container. In this case you can reach the agent through localhost and scale together, but might end up with more than an agent per node, hence my preference for a DaemonSet with an affinity.