kubernetes

package module
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

README

k8s_dns_chaos

Used to inject DNS chaos into a Kubernetes cluster. This is the DNS server for the Chaos Mesh DNSChaos.

Description

This plugin implements the Kubernetes DNS-Based Service Discovery Specification.

CoreDNS running with the k8s_dns_chaos plugin can be used to do chaos tests on DNS.

This plugin can only be used once per Server Block.

Note: It works with CoreDNS 7d5f5b87a4fb310d442f7ef0d52e3fead0e10d39.

Syntax

k8s_dns_chaos [ZONES...]

The k8s_dns_chaos supports all options in plugin kubernetes, besides, it also supports other configuration items for chaos.

kubernetes [ZONES...] {
    endpoint URL
    tls CERT KEY CACERT
    kubeconfig KUBECONFIG CONTEXT
    namespaces NAMESPACE...
    labels EXPRESSION
    pods POD-MODE
    endpoint_pod_names
    ttl TTL
    noendpoints
    transfer to ADDRESS...
    fallthrough [ZONES...]
    ignore empty_service

    chaos ACTION SCOPE [PODS...]
    grpcport PORT
}

Only [ZONES...], chaos and grpcport are different from the kubernetes plugin:

  • [ZONES...] defines which zones of the host will be treated as internal hosts in the Kubernetes cluster.

  • chaos ACTION SCOPE [PODS...] sets the behavior and scope of chaos.

    Valid values for Action:

    • random: return random IP for DNS request.
    • error: return error for DNS request.

    Valid values for SCOPE:

    • inner: chaos only works on the inner host of the Kubernetes cluster.
    • outer: chaos only works on the outer host of the Kubernetes cluster.
    • all: chaos works on all the hosts.

    [PODS...] defines which Pods will take effect, the format is Namespace.PodName.

  • grpcport PORT sets the port of GRPC service, which is used for the hot update of the chaos rules. The default value is 9288. The interface of the GRPC service is defined in dns.proto.

Examples

All DNS requests in Pod busybox.busybox-0 will get error:

k8s_dns_chaos cluster.local in-addr.arpa ip6.arpa {
    pods insecure
    fallthrough in-addr.arpa ip6.arpa
    ttl 30
    chaos error all busybox.busybox-0
}

The shell command below will execute failed:

# Output: ping: bad address 'google.com'
kubectl exec busybox-0 -it -n busybox -- ping -c 1 google.com

Documentation

Overview

Package kubernetes provides the kubernetes backend.

Index

Constants

View Source
const (
	// ScopeInner means chaos only works on the inner host in Kubernetes cluster
	ScopeInner = "inner"
	// ScopeOuter means chaos only works on the outer host of Kubernetes cluster
	ScopeOuter = "outer"
	// ScopeAll means chaos works on all host
	ScopeAll = "all"

	// ActionError means return error for DNS request
	ActionError = "error"
	// ActionRandom means return random IP for DNS request
	ActionRandom = "random"
)
View Source
const (

	// DNSSchemaVersion is the schema version: https://github.com/kubernetes/dns/blob/master/docs/specification.md
	DNSSchemaVersion = "1.1.0"
	// Svc is the DNS schema for kubernetes services
	Svc = "svc"
	// Pod is the DNS schema for kubernetes pods
	Pod = "pod"
)

Variables

View Source
var (

	// DnsProgrammingLatency is defined as the time it took to program a DNS instance - from the time
	// a service or pod has changed to the time the change was propagated and was available to be
	// served by a DNS server.
	// The definition of this SLI can be found at https://github.com/kubernetes/community/blob/master/sig-scalability/slos/dns_programming_latency.md
	// Note that the metrics is partially based on the time exported by the endpoints controller on
	// the master machine. The measurement may be inaccurate if there is a clock drift between the
	// node and master machine.
	// The service_kind label can be one of:
	//   * cluster_ip
	//   * headless_with_selector
	//   * headless_without_selector
	DnsProgrammingLatency = promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
		Namespace: plugin.Namespace,
		Subsystem: pluginName,
		Name:      "dns_programming_duration_seconds",

		Buckets: prometheus.ExponentialBuckets(0.001, 2, 20),
		Help:    "Histogram of the time (in seconds) it took to program a dns instance.",
	}, []string{"service_kind"})
)

Functions

This section is empty.

Types

type Kubernetes

type Kubernetes struct {
	Next          plugin.Handler
	Zones         []string
	Upstream      *upstream.Upstream
	APIServerList []string
	APICertAuth   string
	APIClientCert string
	APIClientKey  string
	ClientConfig  clientcmd.ClientConfig
	APIConn       dnsController
	Namespaces    map[string]struct{}

	Fall fall.F

	TransferTo []string
	Client     typev1.CoreV1Interface

	sync.RWMutex
	// contains filtered or unexported fields
}

Kubernetes implements a plugin that connects to a Kubernetes cluster.

func New

func New(zones []string) *Kubernetes

New returns a initialized Kubernetes. It default interfaceAddrFunc to return 127.0.0.1. All other values default to their zero value, primaryZoneIndex will thus point to the first zone.

func ParseStanza

func ParseStanza(c *caddy.Controller) (*Kubernetes, error)

ParseStanza parses a kubernetes stanza

func (*Kubernetes) AutoPath

func (k *Kubernetes) AutoPath(state request.Request) []string

AutoPath implements the AutoPathFunc call from the autopath plugin. It returns a per-query search path or nil indicating no searchpathing should happen.

func (Kubernetes) CancelDNSChaos

func (k Kubernetes) CancelDNSChaos(ctx context.Context, req *pb.CancelDNSChaosRequest) (*pb.DNSChaosResponse, error)

CancelDNSChaos ...

func (Kubernetes) CreateGRPCServer

func (k Kubernetes) CreateGRPCServer() error

CreateGRPCServer ...

func (*Kubernetes) External

func (k *Kubernetes) External(state request.Request) ([]msg.Service, int)

External implements the ExternalFunc call from the external plugin. It returns any services matching in the services' ExternalIPs.

func (*Kubernetes) ExternalAddress

func (k *Kubernetes) ExternalAddress(state request.Request) []dns.RR

ExternalAddress returns the external service address(es) for the CoreDNS service.

func (*Kubernetes) InitKubeCache

func (k *Kubernetes) InitKubeCache(ctx context.Context) (err error)

InitKubeCache initializes a new Kubernetes cache.

func (*Kubernetes) IsNameError

func (k *Kubernetes) IsNameError(err error) bool

IsNameError implements the ServiceBackend interface.

func (*Kubernetes) Lookup

func (k *Kubernetes) Lookup(ctx context.Context, state request.Request, name string, typ uint16) (*dns.Msg, error)

Lookup implements the ServiceBackend interface.

func (*Kubernetes) Metadata

func (k *Kubernetes) Metadata(ctx context.Context, state request.Request) context.Context

Metadata implements the metadata.Provider interface.

func (*Kubernetes) MinTTL

func (k *Kubernetes) MinTTL(state request.Request) uint32

MinTTL implements the Transferer interface.

func (Kubernetes) Name

func (k Kubernetes) Name() string

Name implements the Handler interface.

func (*Kubernetes) Ready

func (k *Kubernetes) Ready() bool

Ready implements the ready.Readiness interface.

func (*Kubernetes) Records

func (k *Kubernetes) Records(ctx context.Context, state request.Request, exact bool) ([]msg.Service, error)

Records looks up services in kubernetes.

func (*Kubernetes) RegisterKubeCache

func (k *Kubernetes) RegisterKubeCache(c *caddy.Controller)

RegisterKubeCache registers KubeCache start and stop functions with Caddy

func (*Kubernetes) Reverse

func (k *Kubernetes) Reverse(ctx context.Context, state request.Request, exact bool, opt plugin.Options) ([]msg.Service, error)

Reverse implements the ServiceBackend interface.

func (*Kubernetes) Serial

func (k *Kubernetes) Serial(state request.Request) uint32

Serial implements the Transferer interface.

func (Kubernetes) ServeDNS

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

ServeDNS implements the plugin.Handler interface.

func (*Kubernetes) Services

func (k *Kubernetes) Services(ctx context.Context, state request.Request, exact bool, opt plugin.Options) (svcs []msg.Service, err error)

Services implements the ServiceBackend interface.

func (Kubernetes) SetDNSChaos

func (k Kubernetes) SetDNSChaos(ctx context.Context, req *pb.SetDNSChaosRequest) (*pb.DNSChaosResponse, error)

SetDNSChaos ...

func (*Kubernetes) Transfer

func (k *Kubernetes) Transfer(ctx context.Context, state request.Request) (int, error)

Transfer implements the Transferer interface.

type PodInfo

type PodInfo struct {
	Namespace      string
	Name           string
	Action         string
	Scope          string
	Selector       selector.Selector
	IP             string
	LastUpdateTime time.Time
}

PodInfo saves some information for pod

func (*PodInfo) IsOverdue

func (p *PodInfo) IsOverdue() bool

IsOverdue ...

Directories

Path Synopsis
Package object holds functions that convert the objects from the k8s API in to a more memory efficient structures.
Package object holds functions that convert the objects from the k8s API in to a more memory efficient structures.

Jump to

Keyboard shortcuts

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