How to run CoreDNS on Kubernetes Engine?

Problem

Cannot run CoreDNS on Google Kubernetes Engine.
Google Kubernetes Engine defaults to kube-dns for DNS resolution. kube-dns cannot be downscaled to 0 and completely replaced. You want to leverage CoreDNS features that kube-dns does not handle, such as rewriting request names.

Environment

  • Google Kubernetes Engine v1.15.12-gke.9

Solution

If you want to use the caching features that CoreDNS has, you can enable NodeLocal DNSCache which is available on Google Kubernetes Engine v1.15 or later. 

In order to add CoreDNS resolution functionality to your Google Kubernetes Engine cluster, you will have to deploy a core-dns pod, expose it via a service, and configure a stub domain for kube-dns pointing it to the core-dns service IP. This way, all traffic matching the stub domain suffix will get routed to the core-dns pod. The non-matching stub domain traffic will be resolved by kube-dns
Note: This is not a Google Cloud supported solution, but just a possible workaround for providing your Google Kubernetes Engine cluster CoreDNS resolution.  

Cause

Google Kubernetes Engine does not allow kube-dns to be downscaled to 0, so a workaround to use CoreDNS for Google Kubernetes Engine is presented.