kubeforward

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 20 Imported by: ? modules, 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

kubeforward

CoreDNS external plugin for node-local-dns

kubeforward is a CoreDNS plugin designed to dynamically monitor changes in Kubernetes Services and automatically update the list of DNS forwarders. It observes EndpointSlices associated with a specified Service, dynamically adjusting the DNS forwarding configuration as endpoints are added, removed, or updated.

Key Features

  • Dynamic DNS Forwarding Updates: Automatically tracks changes in EndpointSlices, ensuring the DNS forwarding configuration remains current without manual intervention.
  • Enhanced Reliability and Fault Tolerance: In the event of an API server failure, CoreDNS continues to use the last known list of endpoints, maintaining DNS service stability.

Use Case

The kubeforward plugin is particularly useful for organizing a node-local-dns caching mechanism. In the standard scheme, ClusterIP is used as the upstream, delegating load balancing responsibility to the CNI. However, in the event of an API server failure, the CNI may not be aware of which upstream endpoints are alive. kubeforward allows CoreDNS to handle upstream health checks independently and, in the case of an API server failure, it will still retain the list of endpoints and load balance the requests.

Installation

  1. Add the Plugin to CoreDNS:

    • Clone the CoreDNS repository:
      git clone https://github.com/coredns/coredns
      
    • Navigate to the project directory:
      cd coredns
      
    • Add the kubeforward plugin to the plugin.cfg file:
      kubeforward:github.com/deckhouse/coredns-kubeforward
      
      Ensure that this line is added before the forward:forward line to maintain the correct order of plugin execution.
  2. Build CoreDNS with the New Plugin:

    • Execute the following commands:
      go get github.com/deckhouse/coredns-kubeforward
      go generate
      go build
      
      This will generate and build CoreDNS with the kubeforward plugin included.

Configuration

The plugin is configured in the Corefile as follows:

.:53 {
    errors
    log
    kubeforward {
        namespace kube-system
        service_name kube-dns
        port_name dns
        expire 10m
        upstream_read_timeout 5s
        health_check no_rec domain example.org
        prefer_udp
        force_tcp
        slow_threshold 300ms
        slow_log
    }
}

Configuration Parameters

  • namespace (required): Specifies the Kubernetes namespace where the target Service resides.

  • service_name (required): The name of the Service to which DNS queries will be forwarded.

  • port_name: The name of the port in the Service resource responsible for handling DNS queries.

  • expire: Time after which cached connections expire. Default is 10s.

  • upstream_read_timeout: Read timeout for forwarded DNS requests to upstream endpoints. Default is 300s.

  • health_check [no_rec] [domain FQDN]: Partial health check configuration. kubeforward supports:

    • no_rec: send health check queries with RD=false
    • domain FQDN: override the queried domain for health checks

    kubeforward does not support configuring the health check interval because the underlying forward plugin does not expose this setting through a public API. The interval remains the forward default of 500ms.

  • force_tcp: Forces the use of TCP for forwarding queries.

  • prefer_udp: Prefers the use of UDP for forwarding queries.

  • slow_threshold: Duration threshold; DNS queries handled by kubeforward that take longer than this value are counted in slow_requests_total. Set to 0 (default) to disable slow counting.

  • slow_log: When present, logs slow queries (those over slow_threshold) to stdout. The metric slow_requests_total is emitted regardless of this flag.

Metrics

  • coredns_kubeforward_request_duration_seconds{qtype,rcode}: Histogram of request durations.
  • coredns_kubeforward_slow_requests_total{qtype,rcode,upstream}: Counter of requests slower than slow_threshold. To populate the upstream label, include the metadata plugin before kubeforward in the Corefile.

Limitations

Limited Support for Forward Plugin Options: The plugin utilizes the functionality of the forward plugin for serving DNS under the hood but does not support the full list of classic forward options due to the lack of a public interface for configuring options.

License

This project is distributed under the Apache License Version 2.0. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: plugin.Namespace,
		Subsystem: "kubeforward",
		Name:      "request_duration_seconds",
		Help:      "Histogram of DNS request duration in kubeforward, in seconds",
		Buckets:   prometheus.ExponentialBuckets(0.01, 2, 10),
	}, []string{"qtype", "rcode"})

	SlowRequests = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "kubeforward",
		Name:      "slow_requests_total",
		Help:      "Total number of DNS requests slower than the configured threshold",
	}, []string{"qtype", "rcode", "upstream"})
)

Functions

This section is empty.

Types

type KubeForward

type KubeForward struct {
	Next        plugin.Handler
	Namespace   string
	ServiceName string
	// contains filtered or unexported fields
}

KubeForward main struct of plugin

func (*KubeForward) Name

func (df *KubeForward) Name() string

Name return plugin name

func (*KubeForward) ServeDNS

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

func (*KubeForward) UpdateForwardServers

func (df *KubeForward) UpdateForwardServers(newServers []string, config KubeForwardConfig)

UpdateForwardServers update list servers for forward requests

type KubeForwardConfig

type KubeForwardConfig struct {
	Namespace           string
	ServiceName         string
	PortName            string
	Expire              time.Duration
	UpstreamReadTimeout time.Duration
	SlowThreshold       time.Duration
	SlowLogEnabled      bool
	// contains filtered or unexported fields
}

func ParseConfig

func ParseConfig(c *caddy.Controller) (*KubeForwardConfig, error)

ParseConfig parse conf CoreFile

Jump to

Keyboard shortcuts

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