Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time


A CoreDNS plugin that is very similar to k8s_external but supporting all types of Kubernetes external resources - Ingress, Service of type LoadBalancer and HTTPRoutes from the Gateway API project.

This plugin relies on its own connection to the k8s API server and doesn't share any code with the existing kubernetes plugin. The assumption is that this plugin can now be deployed as a separate instance (alongside the internal kube-dns) and act as a single external DNS interface into your Kubernetes cluster(s).


k8s_gateway resolves Kubernetes resources with their external IP addresses based on zones specified in the configuration. This plugin will resolve the following type of resources:

Kind Matching Against External IPs are from
HTTPRoute1 all FQDNs from spec.hostnames matching configured zones gateway.status.addresses2
Ingress all FQDNs from spec.rules[*].host matching configured zones .status.loadBalancer.ingress
Service3 name.namespace + any of the configured zones OR any string consisting of lower case alphanumeric characters, '-' or '.', specified in the annotation (see this for an example) .status.loadBalancer.ingress
VirtualServer4 .status.externalEnpoints.ip

1: Currently supported version of GatewayAPI CRDs is v0.4.0.
2: Gateway is a separate resource specified in the spec.parentRefs of HTTPRoute.
3: Only resolves service of type LoadBalancer
4: Currently supported version of nginxinc kubernetes-ingress is 1.12.3

Currently only supports A-type queries, all other queries result in NODATA responses.

This plugin is NOT supposed to be used for intra-cluster DNS resolution and does not contain the default upstream kubernetes plugin.


The recommended installation method is using the helm chart provided in the repo:

helm repo add k8s_gateway
helm install exdns --set domain=foo k8s_gateway/k8s-gateway

Alternatively, for labbing and testing purposes k8s_gateway can be deployed with a single manifest:

kubectl apply -f


The only required configuration option is the zone that plugin should be authoritative for:

k8s_gateway ZONE 

Additional configuration options can be used to further customize the behaviour of a plugin:

k8s_gateway ZONE 
    resources [RESOURCES...]
    ttl TTL
    apex APEX
    secondary SECONDARY
    kubeconfig KUBECONFIG [CONTEXT]
    fallthrough [ZONES...]
  • resources a subset of supported Kubernetes resources to watch. By default all supported resources are monitored. Available options are [ Ingress | Service | HTTPRoute | VirtualServer ].
  • ttl can be used to override the default TTL value of 60 seconds.
  • apex can be used to override the default apex record value of {ReleaseName}-k8s-gateway.{Namespace}
  • secondary can be used to specify the optional apex record value of a peer nameserver running in the cluster (see Dual Nameserver Deployment section below).
  • kubeconfig can be used to connect to a remote Kubernetes cluster using a kubeconfig file. CONTEXT is optional, if not set, then the current context specified in kubeconfig will be used. It supports TLS, username and password, or token-based authentication.
  • fallthrough if zone matches and no record can be generated, pass request to the next plugin. If [ZONES...] is omitted, then fallthrough happens for all zones for which the plugin is authoritative. If specific zones are listed (for example and, then only queries for those zones will be subject to fallthrough.


k8s_gateway {
    resources Ingress
    ttl 30
    apex exdns-1-k8s-gateway.kube-system
    secondary exdns-2-k8s-gateway.kube-system
    kubeconfig /.kube/config

Dual Nameserver Deployment

Most of the time, deploying a single k8s_gateway instance is enough to satisfy most popular DNS resolvers. However, some of the stricter resolvers expect a zone to be available on at least two servers (RFC1034, section 4.1). In order to satisfy this requirement, a pair of k8s_gateway instances need to be deployed, each with its own unique loadBalancer IP. This way the zone NS record will point to a pair of glue records, hard-coded to these IPs.

Another consideration is that in this case k8s_gateway instances need to know about their peers in order to provide consistent responses (at least the same set of nameservers). Configuration-wise this would require the following:

  1. Two separate k8s_gateway deployments with two separate type: LoadBalancer services in front of them.
  2. No apex override, which would default to releaseName.namespace
  3. A peer nameserver's apex must be included in secondary configuration option
  4. Glue records must match the of each of the running plugin

For example, the above requirements could be satisfied with the following commands:

  1. Install two instances of k8s_plugin gateway pointing at each other:
helm install -n kube-system exdns-1 --set --set secondary=exdns-2.kube-system ./charts/k8s-gateway
helm install -n kube-system exdns-2 --set --set secondary=exdns-1.kube-system ./charts/k8s-gateway
  1. Obtain their external IPs
kubectl -n kube-system get svc -l
NAME                  TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
exdns-1-k8s-gateway   LoadBalancer  53:32122/UDP   5m22s
exdns-2-k8s-gateway   LoadBalancer 53:30009/UDP   4m21s

  1. Delegate the domain from the parent zone by creating a pair of NS records and a pair of glue records pointing to the above IPs: (NS record) -> (A record) -> (NS record) -> (A record) ->


With compile-time configuration file

$ git clone
$ cd coredns
$ vim plugin.cfg
# Replace lines with kubernetes and k8s_external with
$ go generate
$ go build
$ ./coredns -plugins | grep k8s_gateway

With external golang source code

$ git clone
$ cd k8s_gateway
$ go build cmd/coredns.go
$ ./coredns -plugins | grep k8s_external

For more details refer to this CoreDNS doc


Helm Charts

If the change was made only to helm charts, only two things are required:

  • Bump the chart version in ./charts/k8s-gateway/Chart.yaml
  • Run make helm-update


To cut a new plugin release the following is required:

  • Bump the app pluginVersion in ./cmd/coredns.go and commit.
  • Tag the last commit with the save version number.
  • Bump the appVersion and tag in ./charts/k8s-gateway/Chart.yaml and ./charts/k8s-gateway/values.yaml respectively.
  • Run make helm-update


This repository contains a Tiltfile that can be used for local development. To build a local k8s cluster with kind run:

make setup

To bring up a tilt development enviornment run tilt up or:

make up

Some test resources can be added to the k8s cluster with:

# ingress and service resources
kubectl apply -f ./test/ingress-services.yml

# gateway API resources
kubectl apply -f ./test/gateway-api/resources.yml

# nginxinc's VirtualService  resources
kubectl apply -f test/nginxinc-kubernetes-ingress/resources.yaml

Test queries can be sent to the exposed CoreDNS service like this:

$ ip=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}')

# ingress resource
$ dig @$ip -p 32553 +short

# loadBalancer
$ dig @$ip -p 32553 +short

# HTTPRoute/gateway-API
$ dig @$ip -p 32553 +short
$ dig @$ip -p 32553 +short

# multi-gateway HTTPRoute
$ dig @$ip -p 32553 +short

# nginxinc's Ingress
$ dig @$ip -p 32553 +short

# nginxinc's VirtualServer
$ dig @$ip -p 32553 +short

To cleanup local environment do:

make nuke

Also see

Helm repo guide