Commit 28b8a092 authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

Use server block defaults (#894)

* mw/k8s: Test Federation parsing

The test case was there, but there was nothing testing it?!?!?!
Add it and split it out of the main setup test which is too long
already.

Also allow kubernetes a not have a ZONE, just default to the serverblock
in that case. Remove test that was blocking that.

Cleanup up the readme more.

* rewrite README
parent 6e91408f
...@@ -10,8 +10,17 @@ to deploy CoreDNS in Kubernetes](https://github.com/coredns/deployment/tree/mast ...@@ -10,8 +10,17 @@ to deploy CoreDNS in Kubernetes](https://github.com/coredns/deployment/tree/mast
## Syntax ## Syntax
~~~
kubernetes [ZONES...]
~~~
With only the directive specified, the *kubernetes* middleware 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 is specifies
all the zones the middleware should be authoritative for.
``` ```
kubernetes ZONE [ZONE...] [ kubernetes [ZONES...] {
resyncperiod DURATION resyncperiod DURATION
endpoint URL endpoint URL
tls CERT KEY CACERT] tls CERT KEY CACERT]
...@@ -23,7 +32,6 @@ kubernetes ZONE [ZONE...] [ ...@@ -23,7 +32,6 @@ kubernetes ZONE [ZONE...] [
fallthrough fallthrough
} }
``` ```
* `resyncperiod` specifies the Kubernetes data API **DURATION** period. * `resyncperiod` specifies the Kubernetes data API **DURATION** period.
* `endpoint` specifies the **URL** for a remove k8s API endpoint. * `endpoint` specifies the **URL** for a remove k8s API endpoint.
If omitted, it will connect to k8s in-cluster using the cluster service account. If omitted, it will connect to k8s in-cluster using the cluster service account.
...@@ -63,13 +71,10 @@ kubernetes ZONE [ZONE...] [ ...@@ -63,13 +71,10 @@ kubernetes ZONE [ZONE...] [
## Examples ## Examples
**Example 1:** This is a minimal configuration with no options other than zone. It will handle all queries in the `cluster.local` zone and connect to Kubernetes in-cluster, but it will not provide PTR records for services, or A records for pods. Handle all queries in the `cluster.local` zone. Connect to Kubernetes in-cluster.
Als handl all `PTR` requests for `10.0.0.0/16` . Verify the existence of pods when answering pod
kubernetes cluster.local requests. Resolve upstream records against `10.102.3.10`. Note we show the entire server block
here:
**Example 2:** Handle all queries in the `cluster.local` zone. Connect to Kubernetes in-cluster.
Handle all `PTR` requests for `10.0.0.0/16` . Verify the existence of pods when answering pod
requests. Resolve upstream records against `10.102.3.10`.
10.0.0.0/16 cluster.local { 10.0.0.0/16 cluster.local {
kubernetes { kubernetes {
...@@ -78,38 +83,36 @@ kubernetes ZONE [ZONE...] [ ...@@ -78,38 +83,36 @@ kubernetes ZONE [ZONE...] [
} }
} }
**Selective Exposure Example:** Handle all queries in the `cluster.local` zone. Connect to Kubernetes in-cluster. Only expose objects in the test and staging namespaces. Or you can selective expose some namespaces:
Resolve upstream records using the servers configured in `/etc/resolv.conf`.
kubernetes cluster.local { kubernetes cluster.local {
namespaces test staging namespaces test staging
}
**Federation Example:** Handle all queries in the `cluster.local` zone. Connect to Kubernetes in-cluster. Handle federated service requests in the `prod` and `stage` federations. If you want to use federation, just use the `federation` option. Here we handle all service requests
Resolve upstream records using the servers configured in `/etc/resolv.conf`. in the `prod` and `stage` federations. We resolve upstream records using the servers configured in
`/etc/resolv.conf`.
cluster.local { . {
kubernetes { kubernetes cluster.local {
federation prod prod.feddomain.com federation prod prod.feddomain.com
federation stage stage.feddomain.com federation stage stage.feddomain.com
upstream /etc/resolv.conf upstream /etc/resolv.conf
} }
} }
**Out-Of-Cluster Example:** Handle all queries in the `cluster.local` zone. Connect to Kubernetes from outside the cluster. And finally we connect to Kubernetes from outside the cluster:
Verify the existence of pods when answering pod requests. Resolve upstream records against `10.102.3.10`.
kubernetes cluster.local { kubernetes cluster.local {
endpoint https://k8s-endpoint:8443 endpoint https://k8s-endpoint:8443
tls cert key cacert tls cert key cacert
pods verified
upstream 10.102.3.10:53
} }
## Wildcard ## Wildcard
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: 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:
* _service_ in an `A` record request: _service_.namespace.svc.zone. * _service_ in an `A` record request: _service_.namespace.svc.zone.
* e.g. `*.ns.svc.myzone.local` * e.g. `*.ns.svc.myzone.local`
......
...@@ -87,10 +87,6 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) { ...@@ -87,10 +87,6 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
} }
} }
if k8s.Zones == nil || len(k8s.Zones) < 1 {
return nil, errors.New("zone name must be provided for kubernetes middleware")
}
k8s.primaryZone = -1 k8s.primaryZone = -1
for i, z := range k8s.Zones { for i, z := range k8s.Zones {
if strings.HasSuffix(z, "in-addr.arpa.") || strings.HasSuffix(z, "ip6.arpa.") { if strings.HasSuffix(z, "in-addr.arpa.") || strings.HasSuffix(z, "ip6.arpa.") {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment