Answers: <p>This looks to be answered on offcail docs <a href="https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/" rel="nofollow noreferrer">here</a></p>
  <blockquote>
  <p>NodeLocal DNSCache improves Cluster DNS performance by running a dns caching agent on cluster nodes as a DaemonSet.</p>
  <p>With this architecture, Pods will reach out to the dns caching agent running on the same node, thereby avoiding iptables DNAT rules and connection tracking.</p>
  <p><strong>Having a local cache will help improve the latency.</strong></p>
  </blockquote>
  <p><a href="https://i.sstatic.net/UQ3Ur.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UQ3Ur.png" alt="[]" /></a></p>
  <p>Image Reference : <a href="https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/#architecture-diagram" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/#architecture-diagram</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-02-12T13:14:32.890Z
Answers: Thank you. We trialed using the `NodeLocal DNSCache` but found it complicated our network and we saw a increase in DNS timeouts - we never figured out why. I was wondering whether scaling CoreDNS to every Node would give a similar benefit without the increase in complexity.
Answers: Tom
Answers: CC BY-SA 4.0
Answers: 2020-02-12T10:00:37.720Z
Answers: 2020-02-12T10:00:37.720Z
Answers: 2020-06-18T08:28:10.803Z
Answers: DT.
Answers: <p>No, Kubernetes will load-balance requests to a <code>ClusterIP</code> across all Pods with matching labels (and passing readiness checks). It won't keep traffic within the same Node.</p>
  
  <hr>
  
  <p>Q: So how does the NodeLocal DNS Cache achieve to keep DNS requests local to the Node?</p>
  
  <p>A: When using the NodeLocal DNS Cache, it is necessary to pass a extra arg to the Kubelet of each Node (e.g. <code>--kubelet-extra-args "--cluster-dns=169.254.20.10 ..."</code>). This changes the <code>resolv.conf</code> of every container in every Pod to use DNS resolver on the Node, instead of a <code>clusterIP</code>. The NodeLocal Cache runs on every Node (as a DaemonSet) and uses a arg (e.g. <code>"-localip", "169.254.20.10"</code>) to run on the specific IP set in the <code>resolv.conf</code> of all Pods. The NodeLocal DNS Cache Pod also needs to be configured with <code>hostNetwork: true</code>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-02-14T08:58:54.907Z
Answers: Thanks @Tom for crisp and Short explanation.
Answers: DT.
Answers: CC BY-SA 4.0
Answers: 2020-02-13T11:12:11.337Z
Answers: 2020-02-15T17:14:28.813Z
Answers: 2020-02-15T17:14:28.813Z
Answers: Tom
Body: <p>In Kubernetes, if I run a Service <em>Foo</em> on every Node, and also Service <em>Bar</em> on every Node, i.e. with <code>DaemonSets</code>. If a Pod from Service <em>Foo</em> needs to make a request to Service <em>Bar</em>, does Kubernetes networking magic optimise things so communication will be done within the same Node, i.e. without a external network call? Or will a random Pod <em>Bar</em> be picked meaning usually <em>Bar</em> will be on a different Node, so there will be a network hop?</p>
  
  <p><em>Context to question</em>: I'm thinking to run <code>CoreDNS</code> as a <code>Daemonset</code>, because with the <em>cache</em> plugin, I'm hoping most DNS queries will not need to use the network as there will always be a CoreDNS Pod co-located within the same Node and most requests will be cached. Currently we only run 3 CoreDNS pods and we have 12 Nodes and we see some DNS failures at times of network traffic surges - particularly during a deployment when lot of logging is done, which have to be shipped across the network to ElasticSearch.</p>
  
  <hr>
  
  <p>In case specifics matter:</p>
  
  <ul>
  <li>The CoreDNS service runs as <code>clusterIP: 172.20.0.10</code></li>
  <li>The services that use CoreDNS run as <code>type: NodePort</code></li>
  <li>The Kubernetes cluster is AWS EKS, v1.14.9. Networking is done with the AWS VPC CNI.</li>
  </ul>
  
Comments: CC BY-SA 4.0
Comments: 2020-02-12T09:34:43.597Z
Comments: Have you tried [DNS Auto-scaling](https://kubernetes.io/docs/tasks/administer-cluster/dns-horizontal-autoscaling/) if that all what you need to get past the dns failure during network surge ..
Comments: DT.
Tags: <kubernetes><networking><dns>
Title: Does Kubernetes internal networking keep traffic to co-located Pods where possible?
UserDisplayName: Tom
ThreadText: # Does Kubernetes internal networking keep traffic to co-located Pods where possible?
  
  (Asked by: username_0 on 2020-02-12)
  
  In Kubernetes, if I run a Service *Foo* on every Node, and also Service *Bar* on every Node, i.e. with `DaemonSets`. If a Pod from Service *Foo* needs to make a request to Service *Bar*, does Kubernetes networking magic optimise things so communication will be done within the same Node, i.e. without a external network call? Or will a random Pod *Bar* be picked meaning usually *Bar* will be on a different Node, so there will be a network hop?
  
  *Context to question*: I'm thinking to run `CoreDNS` as a `Daemonset`, because with the *cache* plugin, I'm hoping most DNS queries will not need to use the network as there will always be a CoreDNS Pod co-located within the same Node and most requests will be cached. Currently we only run 3 CoreDNS pods and we have 12 Nodes and we see some DNS failures at times of network traffic surges - particularly during a deployment when lot of logging is done, which have to be shipped across the network to ElasticSearch.
  
  ---
  
  In case specifics matter:
  
  * The CoreDNS service runs as `clusterIP: 172.20.0.10`
  * The services that use CoreDNS run as `type: NodePort`
  * The Kubernetes cluster is AWS EKS, v1.14.9. Networking is done with the AWS VPC CNI.
  
  **Tags:** kubernetes, networking, dns
  
  > **Comments:**
  > **username_1**: Have you tried [DNS Auto-scaling](https://kubernetes.io/docs/tasks/administer-cluster/dns-horizontal-autoscaling/) if that all what you need to get past the dns failure during network surge ..  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-02-13. Score: 3 | Accepted answer
  
  No, Kubernetes will load-balance requests to a `ClusterIP` across all Pods with matching labels (and passing readiness checks). It won't keep traffic within the same Node.
  
  ---
  
  Q: So how does the NodeLocal DNS Cache achieve to keep DNS requests local to the Node?
  
  A: When using the NodeLocal DNS Cache, it is necessary to pass a extra arg to the Kubelet of each Node (e.g. `--kubelet-extra-args "--cluster-dns=169.254.20.10 ..."`). This changes the `resolv.conf` of every container in every Pod to use DNS resolver on the Node, instead of a `clusterIP`. The NodeLocal Cache runs on every Node (as a DaemonSet) and uses a arg (e.g. `"-localip", "169.254.20.10"`) to run on the specific IP set in the `resolv.conf` of all Pods. The NodeLocal DNS Cache Pod also needs to be configured with `hostNetwork: true`.
  
  > **Comments:**
  > **username_1**: Thanks @username_0 for crisp and Short explanation.  
  
  ---
  
  ### Answer by username_1 on 2020-02-12. Score: 2
  
  This looks to be answered on offcail docs [here](https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/)
  
  > NodeLocal DNSCache improves Cluster DNS performance by running a dns caching agent on cluster nodes as a DaemonSet.
  >
  > With this architecture, Pods will reach out to the dns caching agent running on the same node, thereby avoiding iptables DNAT rules and connection tracking.
  >
  > **Having a local cache will help improve the latency.**
  
  [![[]](https://i.sstatic.net/UQ3Ur.png)](https://i.sstatic.net/UQ3Ur.png)
  
  Image Reference : <https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/#architecture-diagram>
  
  > **Comments:**
  > **username_0**: Thank you. We trialed using the `NodeLocal DNSCache` but found it complicated our network and we saw a increase in DNS timeouts - we never figured out why. I was wondering whether scaling CoreDNS to every Node would give a similar benefit without the increase in complexity.  
  
  ---
  
  