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).
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 modifyConfigMap
forCoreDNS
as it's described in CoreDNS documentation.After that, you would need to reload
CoreDNS
configuration to apply new configuration fromConfigMap
. To achieve that, you can usereload plugin
forCoreDNS
. More details about this plugin can be found here.Instead of above you can consider using
sidecarContainer
forCoreDNS
, which will sendSIGUSR1
signal toCoreDNS
conatiner. Example of this method can be found in this Github thread.