k8scrd

package module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

k8s_crd

A CoreDNS plugin that is very similar to k8s_external but supporting DNSEndpoint external resource.

This project is a modification of k8s_gateway plugin, adopted with DNSEndpoint client.

This plugin relies on it's 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).

Description

k8s_crd 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
DNSEndpoint FQDNs from .spec.endpoints[].dnsName matching configured zones .spec.endpoints[].targets

Supports A and TXT queries, plus zone-apex SOA and NS responses. Other query types can return NODATA responses.

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

Install

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

helm install exdns ./charts/coredns

Configure

k8s_crd [ZONE...]

Optionally, you can specify what kind of resources to watch, default TTL to return in response and a default name to use for zone apex, e.g.

k8s_crd example.com {
    ttl 10
    apex dns1
}

Resolving order

GeoIP

In case dnsEndpoint object's target has a label of strategy: geoip CoreDNS k8s_crd plugin will respond in a special way:

  • Assuming record has multiple IPs associated with it, and DNS message comes with edns0 CLIENT-SUBNET option.
  • CoreDNS will compare the specified field tag(s) for IP extracted from CLIENT-SUBNET option against available Endpoint.Targets
  • Return only IPs where tags match
  • If IP has no common tag, all entries are returned.
  • CoreDNS must be supplied with a specially crafted GeoIP database in MaxMind DB format and mounted (at /geoip.mmdb by default, configured via the geodatafilepath plugin option). Refer to ./terratest/geogen for examples. Using the MaxMind GeoLite2 database is supported using the necessary geodatafield to configure the field to use as required.
Single Field Matching

For simple GeoIP matching using a single field:

k8s_crd example.com {
    geodatafilepath /geoip.mmdb
    geodatafield country.iso_code
    ...
}
Hierarchical Multi-Level Matching

For hierarchical matching with multiple fields in priority order, use geodatafields (plural). The plugin will try each field in order and return matches from the first field that produces results:

k8s_crd example.com {
    geodatafilepath /geoip.mmdb
    geodatafields country.iso_code continent.code
    ...
}

Note: If both geodatafield and geodatafields are specified, geodatafields takes precedence. For backward compatibility, geodatafield (singular) is still supported.

Weight Round Robin

To enable the weight round robin you have to set the configuration to weight load-balancer:

k8s_crd example.com {
    loadbalance weight
    ...
}

The dnsEndpoint must also contain information about the percentage distribution per region and their IP addresses. Thanks to this, the weight round-robin module will know in which order to return IP addresses. Addresses with high probability will often be at the top of DNS responses, while those with low probability will be at the bottom.

labels:
    strategy: roundrobin
    weight-eu-0-50: 10.0.0.1
    weight-eu-1-50: 10.0.0.2
    weight-za-0-0:  10.10.0.1
    weight-us-0-50: 10.20.0.1

For more information about balancing, please visit our go-weight-shuffling module.

Build

See CONTRIBUTING.md for toolchain requirements, a build from a fresh checkout, tests, defect reporting, and review requirements. See ARCHITECTURE.md for component and interface documentation, DEPENDENCY.md for dependency management, and SECURITY.md for private vulnerability reporting and security updates.

With compile-time configuration file
git clone https://github.com/coredns/coredns
cd coredns
vim plugin.cfg
# Replace lines with kubernetes and k8s_external with k8s_crd:github.com/k8gb-io/coredns-crd-plugin
go generate
go build
./coredns -plugins | grep k8s_crd
With external golang source code
git clone https://github.com/k8gb-io/coredns-crd-plugin.git
cd coredns-crd-plugin
go build cmd/coredns.go
./coredns -plugins | grep k8s_crd

For more details refer to this CoreDNS doc

Notes regarding Zone Apex and NS server resolution

Due to the fact that there is not nice way to discover NS server's own IP to respond to A queries, as a workaround, it's possible to pass the name of the LoadBalancer service used to expose the CoreDNS instance as an environment variable EXTERNAL_SVC. If not set, the default fallback value of external-dns.kube-system will be used to look up the external IP of the CoreDNS service.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunKubeController

func RunKubeController(ctx context.Context, cfg *restclient.Config, filters []string) (*k8sctrl.KubeController, error)

RunKubeController kicks off the k8s controllers

Types

type K8sCRD

type K8sCRD struct {
	Next   plugin.Handler
	Filter string
	// contains filtered or unexported fields
}

func NewK8sCRD

func NewK8sCRD(ct configType, filters []string) (*K8sCRD, error)

func (*K8sCRD) Name

func (p *K8sCRD) Name() string

func (*K8sCRD) ServeDNS

func (p *K8sCRD) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handle interface.

Directories

Path Synopsis
common
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
wrr
terratest
geogen command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址