gateway

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

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
DNSEndponit all FQDNs from spec.endpoints.dnszone matching configured zones .spec.endpoints.dnszone.targets

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.

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 {
    resources DNSEndpoint
    ttl 10
    apex dns1
}

Resolving order

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 DC tag 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 as /geoip.mmdb Refer to ./terratest/geogen for examples.

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_crd:github.com/absaoss/k8s_crd
$ go generate
$ go build
$ ./coredns -plugins | grep k8s_crd
With external golang source code
$ git clone https://github.com/absaoss/k8s_crd.git
$ cd k8s_crd
$ 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 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.

Documentation

Overview

Copyright 2021 ABSA Group Limited

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic

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

	Filter           string
	Annotation       string
	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, ttl endpoint.TTL) (records []dns.RR)

A generates dns.RR for A record

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.

func (*Gateway) TXT added in v0.0.9

func (gw *Gateway) TXT(state request.Request, results []string, ttl endpoint.TTL) (records []dns.RR)

TXT generates dns.RR for TXT record

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, c *Gateway) (*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
terratest

Jump to

Keyboard shortcuts

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