loadbalancer

package module
v0.0.0-...-a0ad386 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

Kubernetes LoadBalancer

Name

k8s_loadbalancer - Exports Services of type LoadBalancer to external DNS

Description

The plugin currently takes services of type LoadBalancer from all namespaces and exports it to the .kube. zone. For example:

  Service Name: test-wordpress
  DNS: test-wordpress.kube

This can be configured as shown in the configuration section below.

Compilation

This package will always be compiled as part of CoreDNS and not in a standalone way. It will require you to use go get or as a dependency on plugin.cfg.

The manual will have more information about how to configure and extend the server with external plugins.

A simple way to consume this plugin, is by adding the following on plugin.cfg, and recompile it as detailed on coredns.io.

k8s_loadbalancer:k8s_loadbalancer

Put this early in the plugin list, so that example is executed before any of the other plugins.

After this you can compile coredns by:

go generate
go build

Or you can instead use make:

make

Syntax

example

Metrics

If monitoring is enabled (via the prometheus directive) the following metric is exported:

  • coredns_example_request_count_total{server} - query count to the example plugin.

The server label indicated which server handled the request, see the metrics plugin for details.

Ready

This plugin reports readiness to the ready plugin. It will be immediately ready.

Examples

In this configuration, we forward all queries to 8.8.8.8 and resolve anything going to the .kube zone.

. {
  k8s_loadbalancer
  forward . 8.8.8.8
  debug
}

Or without any external connectivity:

. {
  k8s_loadbalancer
}

Without any zones being specified, the plugin will default to the .kube. zone. Additional zones can be added as below (This will add the test, and test2 zones)

. {
  k8s_loadbalancer .test. .test2. {
        enableNSZone true
        enableRootZone true
        kubeConfigPath /path/to/.kube/config
  }
}

Additonally Namespace Zones can be enabled for example:

service.namespace.zone 

This can be done using the enableNSZone flag (true/false)

Also See

See the manual.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadBalancer

type LoadBalancer struct {
	PluginReady    bool
	KubeConfigPath string
	EnableRootZone bool
	EnableNSZone   bool
	RootZones      []string
	RecordsSync    *sync.Mutex
	Records        []kubeRecord
	Next           plugin.Handler
}

LoadBalancer is a plugin to show how to write a plugin.

func NewLoadBalancer

func NewLoadBalancer() *LoadBalancer

func (LoadBalancer) Name

func (e LoadBalancer) Name() string

Name implements the Handler interface.

func (LoadBalancer) Ready

func (e LoadBalancer) Ready() bool

Ready implements the ready.Readiness interface, once this flips to true CoreDNS assumes this plugin is ready for queries; it is not checked again.

func (LoadBalancer) RemoveZoneSuffix

func (e LoadBalancer) RemoveZoneSuffix(name string, suffix []string) string

func (LoadBalancer) ServeDNS

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

ServeDNS implements the plugin.Handler interface. This method gets called when kube zone is used in a Server.

type ResponsePrinter

type ResponsePrinter struct {
	dns.ResponseWriter
}

ResponsePrinter wrap a dns.ResponseWriter and will write example to standard output when WriteMsg is called.

func NewResponsePrinter

func NewResponsePrinter(w dns.ResponseWriter) *ResponsePrinter

NewResponsePrinter returns ResponseWriter.

func (*ResponsePrinter) WriteMsg

func (r *ResponsePrinter) WriteMsg(res *dns.Msg) error

WriteMsg calls the underlying ResponseWriter's WriteMsg method and prints "example" to standard output.

Jump to

Keyboard shortcuts

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