2

I setup a private K8S cluster with RKE 1.2.2 and so my K8S version is 1.19. We have some internal services, and it is necessary to access each other using custom FQDN instead of simple service names. As I searched the web, the only solution I found is adding rewrite records for CoreDNS ConfigMap described in this REF. However, this solution results in manual configuration, and I want to define a record automatically during service setup. Is there any solution for this automation? Does CoreDNS have such an API to add or delete rewrite records?

Note1: I also tried to mount the CoreDNS's ConfigMap and update it via another pod, but the content is mounted read-only.

Note2: Someone proposed calling kubectl get cm -n kube-system coredns -o yaml | sed ... | kubectl apply .... However, I want to automate it during service setup or in a pod or in an initcontainer.

Note3: I wish there were something like hostAliases for services, something called serviceAliases for internal services (ClusterIP).

Mehdi Bizhani
  • 21
  • 1
  • 5
  • In short, you were able to achieve what you want, but you are looking some kind of automation? You are looking pure kubernetes way or 3rd party software solution? – PjoterS Dec 15 '20 at 13:46
  • You are correct, PjoterS. I just want an automated way, and as you said, pure kubernetes way or 3rd party software solution is fine. Even, I'm ready to develop the code if there is any CoreDNS's API for the matter. – Mehdi Bizhani Dec 15 '20 at 16:21

1 Answers1

0

Currently, there is no ready solution for this.

Only thing comes to my mind is to use MutatingAdmissionWebhook. It would need catch moment, when new Kubernetes service was created and then modify ConfigMap for CoreDNS as it's described in CoreDNS documentation.

After that, you would need to reload CoreDNS configuration to apply new configuration from ConfigMap. To achieve that, you can use reload plugin for CoreDNS. More details about this plugin can be found here.

Instead of above you can consider using sidecarContainer for CoreDNS, which will send SIGUSR1 signal to CoreDNS conatiner. Example of this method can be found in this Github thread.

PjoterS
  • 12,841
  • 1
  • 22
  • 54