coredns/plugin/kubernetes
Miek Gieben 9546b606cb
K8s remove string ops (#2119)
* plugin/kubernetes: remove bunch a string ops

This removes a bunch of appends to where not needed, makes dnsutil.Join
take variadic args which removes the need to wrap in a new string slice.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Fix calls to dnsutil.Join

Signed-off-by: Miek Gieben <miek@miek.nl>

* Revert these

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-09-22 15:12:02 +01:00
..
apiproxy.go Use logging (#1718) 2018-04-22 21:40:33 +01:00
autopath.go Typo fixes (#2031) 2018-08-14 08:55:55 -07:00
controller.go K8s remove string ops (#2119) 2018-09-22 15:12:02 +01:00
controller_test.go Watch feature (#1527) 2018-06-27 07:45:32 -07:00
federation.go K8s remove string ops (#2119) 2018-09-22 15:12:02 +01:00
handler.go Default to scrubbing replies in the server (#2012) 2018-08-29 12:26:22 +01:00
handler_ignore_emptyservice_test.go Makefile fixes: (#1892) 2018-06-21 04:34:02 -07:00
handler_pod_disabled_test.go all: fix plugin import ordering (#1717) 2018-04-22 08:34:35 +01:00
handler_pod_insecure_test.go handle blank name and namespaces (#2042) 2018-08-27 19:41:04 +01:00
handler_pod_verified_test.go all: fix plugin import ordering (#1717) 2018-04-22 08:34:35 +01:00
handler_test.go handle blank name and namespaces (#2042) 2018-08-27 19:41:04 +01:00
health.go plugin/health: implement dyn health checks (#1214) 2017-11-13 09:52:40 +00:00
kubernetes.go K8s remove string ops (#2119) 2018-09-22 15:12:02 +01:00
kubernetes_apex_test.go all: fix plugin import ordering (#1717) 2018-04-22 08:34:35 +01:00
kubernetes_test.go Watch feature (#1527) 2018-06-27 07:45:32 -07:00
local.go Plugin/Kubernetes: Service and Endpoint Indexing (#1149) 2017-10-17 21:30:54 -04:00
log_test.go Clean up tests logging (#1979) 2018-07-19 16:23:06 +01:00
namespace.go plugin/kubernetes: correctly set NODATA for ns (#1229) 2017-11-13 21:51:51 +00:00
ns.go Update k8s client-go to v6.0.0 (#1340) 2018-01-03 11:11:28 +00:00
ns_test.go Watch feature (#1527) 2018-06-27 07:45:32 -07:00
OWNERS Add OWNERS file (#1486) 2018-02-08 10:55:51 +00:00
parse.go handle blank name and namespaces (#2042) 2018-08-27 19:41:04 +01:00
parse_test.go fix kubernetes in-cluster CNAME lookup (#2040) 2018-08-25 08:53:41 -04:00
README.md Cleanup ParseHostOrFile (#2100) 2018-09-19 07:29:37 +01:00
reverse.go plugin/kubernetes: PTR/A reverse query corner cases (#1551) 2018-02-28 07:53:12 -08:00
reverse_test.go Watch feature (#1527) 2018-06-27 07:45:32 -07:00
setup.go plugin/forward: add REFUSED test (#1878) 2018-06-15 08:12:56 -07:00
setup_reverse_test.go reqd changes (#1522) 2018-02-12 14:27:16 -05:00
setup_test.go Typo fixes (#2031) 2018-08-14 08:55:55 -07:00
setup_ttl_test.go reqd changes (#1522) 2018-02-12 14:27:16 -05:00
watch.go Watch feature (#1527) 2018-06-27 07:45:32 -07:00
watch_test.go Watch feature (#1527) 2018-06-27 07:45:32 -07:00
xfr.go plugin/kubernetes: dont transfer unexposed namespaces (#2044) 2018-08-27 10:38:49 -04:00
xfr_test.go plugin/kubernetes: dont transfer unexposed namespaces (#2044) 2018-08-27 10:38:49 -04:00

kubernetes

Name

kubernetes - enables the reading zone data from a Kubernetes cluster.

Description

It implements the Kubernetes DNS-Based Service Discovery Specification.

CoreDNS running the kubernetes plugin can be used as a replacement of kube-dns in a kubernetes cluster. See the deployment repository for details on how to deploy CoreDNS in Kubernetes.

stubDomains and upstreamNameservers are implemented via the proxy plugin and kubernetes upstream. See example below.

This plugin can only be used once per Server Block.

Syntax

kubernetes [ZONES...]

With only the directive specified, the kubernetes plugin will default to the zone specified in the server's block. It will handle all queries in that zone and connect to Kubernetes in-cluster. It will not provide PTR records for services, or A records for pods. If ZONES is used it specifies all the zones the plugin should be authoritative for.

kubernetes [ZONES...] {
    resyncperiod DURATION
    endpoint URL [URL...]
    tls CERT KEY CACERT
    namespaces NAMESPACE...
    labels EXPRESSION
    pods POD-MODE
    endpoint_pod_names
    upstream [ADDRESS...]
    ttl TTL
    transfer to ADDRESS...
    fallthrough [ZONES...]
}
  • resyncperiod specifies the Kubernetes data API DURATION period.

  • endpoint specifies the URL for a remote k8s API endpoint. If omitted, it will connect to k8s in-cluster using the cluster service account. Multiple k8s API endpoints could be specified: endpoint http://k8s-endpoint1:8080 http://k8s-endpoint2:8080. CoreDNS will automatically perform a healthcheck and proxy to the healthy k8s API endpoint.

  • tls CERT KEY CACERT are the TLS cert, key and the CA cert file names for remote k8s connection. This option is ignored if connecting in-cluster (i.e. endpoint is not specified).

  • namespaces NAMESPACE [NAMESPACE...], only exposes the k8s namespaces listed. If this option is omitted all namespaces are exposed

  • labels EXPRESSION only exposes the records for Kubernetes objects that match this label selector. The label selector syntax is described in the Kubernetes User Guide - Labels. An example that only exposes objects labeled as "application=nginx" in the "staging" or "qa" environments, would use: labels environment in (staging, qa),application=nginx.

  • pods POD-MODE sets the mode for handling IP-based pod A records, e.g. 1-2-3-4.ns.pod.cluster.local. in A 1.2.3.4. This option is provided to facilitate use of SSL certs when connecting directly to pods. Valid values for POD-MODE:

    • disabled: Default. Do not process pod requests, always returning NXDOMAIN
    • insecure: Always return an A record with IP from request (without checking k8s). This option is vulnerable to abuse if used maliciously in conjunction with wildcard SSL certs. This option is provided for backward compatibility with kube-dns.
    • verified: Return an A record if there exists a pod in same namespace with matching IP. This option requires substantially more memory than in insecure mode, since it will maintain a watch on all pods.
  • endpoint_pod_names uses the pod name of the pod targeted by the endpoint as the endpoint name in A records, e.g. endpoint-name.my-service.namespace.svc.cluster.local. in A 1.2.3.4 By default, the endpoint-name name selection is as follows: Use the hostname of the endpoint, or if hostname is not set, use the dashed form of the endpoint IP address (e.g. 1-2-3-4.my-service.namespace.svc.cluster.local.) If this directive is included, then name selection for endpoints changes as follows: Use the hostname of the endpoint, or if hostname is not set, use the pod name of the pod targeted by the endpoint. If there is no pod targeted by the endpoint, use the dashed IP address form.

  • upstream [ADDRESS...] defines the upstream resolvers used for resolving services that point to external hosts (aka External Services aka CNAMEs). If no ADDRESS is given, CoreDNS will resolve External Services against itself. ADDRESS can be an IP, an IP:port, or a path to a file structured like resolv.conf.

  • ttl allows you to set a custom TTL for responses. The default (and allowed minimum) is to use 5 seconds, the maximum is capped at 3600 seconds.

  • noendpoints will turn off the serving of endpoint records by disabling the watch on endpoints. All endpoint queries and headless service queries will result in an NXDOMAIN.

  • transfer enables zone transfers. It may be specified multiples times. To signals the direction (only to is allow). ADDRESS must be denoted in CIDR notation (127.0.0.1/32 etc.) or just as plain addresses. The special wildcard * means: the entire internet. Sending DNS notifies is not supported. Deprecated pod records in the sub domain pod.cluster.local are not transferred.

  • fallthrough [ZONES...] If a query for a record in the zones for which the plugin is authoritative results in NXDOMAIN, normally that is what the response will be. However, if you specify this option, the query will instead be passed on down the plugin chain, which can include another plugin to handle the query. If [ZONES...] is omitted, then fallthrough happens for all zones for which the plugin is authoritative. If specific zones are listed (for example in-addr.arpa and ip6.arpa), then only queries for those zones will be subject to fallthrough.

  • ignore empty_service return NXDOMAIN for services without any ready endpoint addresses (e.g. ready pods). This allows the querying pod to continue searching for the service in the search path. The search path could, for example, include another kubernetes cluster.

Health

This plugin implements dynamic health checking. Currently this is limited to reporting healthy when the API has synced.

Watch

This plugin implements watch. A client that connects to CoreDNS using coredns/client can be notified of changes to A, AAAA, and SRV records for Kubernetes services and endpoints.

Examples

Handle all queries in the cluster.local zone. Connect to Kubernetes in-cluster. Also handle all in-addr.arpa PTR requests for 10.0.0.0/17 . Verify the existence of pods when answering pod requests. Resolve upstream records against 10.102.3.10. Note we show the entire server block here:

10.0.0.0/17 cluster.local {
    kubernetes {
        pods verified
        upstream 10.102.3.10:53
    }
}

Or you can selectively expose some namespaces:

kubernetes cluster.local {
    namespaces test staging
}

Connect to Kubernetes with CoreDNS running outside the cluster:

kubernetes cluster.local {
    endpoint https://k8s-endpoint:8443
    tls cert key cacert
}

stubDomains and upstreamNameservers

Here we use the proxy plugin to implement a stubDomain that forwards example.local to the nameserver 10.100.0.10:53. The upstream option in kubernetes means that ExternalName services (CNAMEs) will be resolved using the respective proxy. Also configured is an upstreamNameserver 8.8.8.8:53 that will be used for resolving names that do not fall in cluster.local or example.local.

.:53 {
    kubernetes cluster.local {
        upstream
    }
    proxy example.local 10.100.0.10:53
    proxy . 8.8.8.8:53
}

The configuration above represents the following Kube-DNS stubDomains and upstreamNameservers configuration.

  stubDomains: |
    {“example.local”: [“10.100.0.10:53”]}
  upstreamNameservers: |
    [“8.8.8.8:53”]

AutoPath

The kubernetes plugin can be used in conjunction with the autopath plugin. Using this feature enables server-side domain search path completion in kubernetes clusters. Note: pods must be set to verified for this to function properly.

cluster.local {
    autopath @kubernetes
    kubernetes {
        pods verified
    }
}

Federation

The kubernetes plugin can be used in conjunction with the federation plugin. Using this feature enables serving federated domains from the kubernetes clusters.

cluster.local {
    federation {
        prod prod.example.org
        staging staging.example.org
    }
    kubernetes
}

Wildcards

Some query labels accept a wildcard value to match any value. If a label is a valid wildcard (*, or the word "any"), then that label will match all values. The labels that accept wildcards are:

  • endpoint in an A record request: endpoint.service.namespace.svc.zone, e.g. *.nginx.ns.svc.cluster.local
  • service in an A record request: service.namespace.svc.zone, e.g. *.ns.svc.cluster.local
  • namespace in an A record request: service.namespace.svc.zone, e.g. nginx.*.svc.cluster.local
  • port and/or protocol in an SRV request: _port._protocol.service.namespace.svc.zone., e.g. _http.*.service.ns.svc.cluster.local
  • multiple wild cards are allowed in a single query, e.g. A Request *.*.svc.zone. or SRV request *.*.*.*.svc.zone.

For example, Wildcards can be used to resolve all Endpoints for a Service as A records. e.g.: *.service.ns.svc.myzone.local will return the Endpoint IPs in the Service service in namespace default:

*.service.default.svc.cluster.local. 5	IN A	192.168.10.10
*.service.default.svc.cluster.local. 5	IN A	192.168.25.15

This response can be randomized using the loadbalance plugin