When I deploy a new service into a namespace, I need to create a new DNS record that makes it available. I’ve previously talked about using CoreDNS to host my lab DNS zones, but this is something different. I want to make a Kubernetes Service available using an existing Microsoft DNS server - which is already used by all the clients who would need to access the service.
To do this I will create a delegated zone under my existing zone
cmbu.local that CoreDNS will be responsible for. Then I will use the
k8s_gateway plugin to automatically create records for Services provisioned within my zone.
k8s_gateway plugin for CoreDNS automatically creates a DNS record based on the name of the service and it’s namespace, into a zone that you specify. If I create a CoreDNS zone called
myzone.com and then deploy a
my-lb in a namespace called
my-namespace will create a corresponding DNS record of
There’s a handy
helm chart to deploy a separate instance of CoreDNS with the plugin configured. By passing the
domain value I can configure a zone in which the records for my Services will automatically be created.
With my Kuberentes context pointed at my namespace, I clone the
k8s_gateway repository, and deploy the helm chart:
This deploys a new instance of CoreDNS and exposes it with a service, to get the IP address of the new service I use
kubectl get services
Next I create the delgated zone within my Microsoft DNS zone:
The subdomain will be part of the generated DNS name - in my case
You can either create an A record for your CoreDNS instance, then add and resolved the FQDN, or manually add a Server FQDN (in my case I just used the generated one) and then add the Service’s IP address from the
kubectl output above.
To validate this is working and to test my new dynamically generated DNS record, I’ve deployed a new service called
oc-smcgeown - you can see it in the output of the command below:
All being well, my DNS record
service-name.namespace-name.moad.cmbu.local should be responding: