Make coredns responses depend on client namespaces in k8s cluster

7/5/2018

How to make coredns to respond with different IP addresses for the same domain query from different namespaces in k8s cluster?

I'd like it behaves like this:

namespace A (inside k8s cluster):
domainabc.foo.barquery  —— coredns1---—> response 192.168.0.100 (outside k8s cluster)

namespace B (inside k8s cluster):
domainabc.foo.barquery  —— coredns1---—> response 192.168.0.101 (outside k8s cluster)

namespace C (inside k8s cluster):
domainabc.foo.barquery  —— coredns1---—> response 192.168.0.102 (outside k8s cluster)
-- jerrypicasso
coredns
dns
kubernetes

1 Answer

7/6/2018

CoreDNS in the default installation is not able to serve different zones depending on the origin of namespaces the query is coming from. To achieve different answers provided by CoreDNS for different incoming queries based on namespace, you need to create separate instances of CoreDNS for individual namespaces. The second problem is the need of CoreDNS to cache answers. To achieve it for different queries, it is required to have separate caches.

Good news is - CoreDNS is providing an interface for plugins, so you can write plugins for your purposes by your own.

-- d0bry
Source: StackOverflow