gateway

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

README

k8s_gateway

A CoreDNS plugin that is very similar to k8s_external but supporting all types of Kubernetes external resources - Ingress, Service of type LoadBalancer and networking.x-k8s.io/Gateway (when it becomes available).

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_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
Ingress all FQDNs from spec.rules[*].host matching configured zones .status.loadBalancer.ingress
Service[*] name.namespace + any of the configured zones .status.loadBalancer.ingress

[*]: Only resolves service of type LoadBalancer

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.

Configure

k8s_gateway [ZONE...] 

Optionally, you can specify what kind of resources to watch and the default TTL to return in response, e.g.

k8s_gateway example.com {
    resources Ingress
    ttl 10
}

Build

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_gateway:github.com/ori-edge/k8s_gateway
$ go generate
$ go build
$ ./coredns -plugins | grep k8s_gateway
With external golang source code
$ git clone https://github.com/ori-edge/k8s_external
$ cd k8s_gateway
$ go build cmd/coredns.go
$ ./coredns -plugins | grep k8s_external

For more details refer to this CoreDNS doc

Hack

This repository contains a Tiltfile that can be used for local development. To setup a local environment do:

make up

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

kubectl apply -f ./test/test.yml

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

$ ip=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}')
$ dig @$ip -p 32553 myservicea.foo.org +short
172.18.0.2
$ dig @$ip -p 32553 test.default.foo.org +short
192.168.1.241

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 wokaround, 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.

Also see

Blogpost

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

type Gateway struct {
	Next      plugin.Handler
	Zones     []string
	Resources []*resourceWithIndex

	Controller *KubeController

	ExternalAddrFunc func(request.Request) []dns.RR
	// contains filtered or unexported fields
}

Gateway stores all runtime configuration of a plugin

func (*Gateway) A

func (gw *Gateway) A(state request.Request, results []net.IP) (records []dns.RR)

A does the A-record lookup in ingress indexer

func (*Gateway) Name

func (gw *Gateway) Name() string

Name implements the Handler interface.

func (*Gateway) SelfAddress

func (gw *Gateway) SelfAddress(state request.Request) (records []dns.RR)

func (*Gateway) ServeDNS

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

ServeDNS implements the plugin.Handle interface.

type KubeController

type KubeController struct {
	// contains filtered or unexported fields
}

KubeController stores the current runtime configuration and cache

func RunKubeController

func RunKubeController(ctx context.Context) (*KubeController, error)

RunKubeController kicks off the k8s controllers

func (*KubeController) HasSynced

func (ctrl *KubeController) HasSynced() bool

HasSynced returns true if all controllers have been synced

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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