k3d icon indicating copy to clipboard operation
k3d copied to clipboard

[FEATURE] Allow CoreDNS extension with custom configuration

Open johgoe opened this issue 4 years ago • 9 comments

We want to add add a custom core dns configuration

e.g.

rewrite name regex (.*)\.local\.kyma\.dev istio-ingressgateway.istio-system.svc.cluster.local

to core dns configmap. Currently we have to patch the coredns configmap after every start again.

johgoe avatar Oct 25 '21 07:10 johgoe

I saw in an different product a coredns configuration like this one

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        ready
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
        import custom/*.override
    }
    import custom/*.server

which allows overides by imports (https://coredns.io/plugins/import/)

Maybe this could be a solution to solve this feature request.

johgoe avatar Oct 25 '21 07:10 johgoe

Hi @johgoe , thanks for opening this issue and thanks for the suggestion. In fact, I'm currently discussing this with the K3s developers. More concretely, I'd like to get https://github.com/k3s-io/k3s/pull/743 revived, so we don't have to hack this into k3d (as K3s does some templating etc. when rendering the CoreDNS template on K3s server startup). Maybe you can add your opinion and input (e.g. the wildcard way you proposed) there? :+1:

iwilltry42 avatar Oct 25 '21 09:10 iwilltry42

I added a note to https://github.com/k3s-io/k3s/issues/462

johgoe avatar Oct 25 '21 19:10 johgoe

Following up on this in https://github.com/k3s-io/k3s/pull/4397

iwilltry42 avatar Nov 08 '21 09:11 iwilltry42

Moving this to Milestone v5.5.0 as I'd like to integrate it with some larger changes that require detecting the used K3s version first and matching it against a map of supported features.

iwilltry42 avatar Mar 26 '22 09:03 iwilltry42

Is there any new status on this? It seems that adding coredns-custom config map does something, but I couldn't get it to rewrite my domains. Adding the same entry into the main server block works immediately.

rassie avatar Jul 22 '22 12:07 rassie

Is there any new status on this? It seems that adding coredns-custom config map does something, but I couldn't get it to rewrite my domains. Adding the same entry into the main server block works immediately.

I'm facing the same issue. I don't know that much about coredns, if I patch the ConfigMap to add a rewrite in the Corefile before the kubernetes plugin, my rule works fine. But if I create a coredns-custom ConfigMap with a server and the same rewrite, my requests fail.

The patched main ConfigMap that works:

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        ready
        # That rewrite rule is working fine in the Corefile
        rewrite name my-internal.domain.com host.k3d.internal
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        # etc...

My attempt with a custom ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns-custom
  namespace: kube-system
data:
  my-internal.domain.server: |
    my-internal.domain.com {
        log
        rewrite name my-internal.domain.com host.k3d.internal
    }

Am I doing it wrong?

Edit: I added the errors plugin in my server block, and the rewrite plugin returns an error in the coredns logs: [ERROR] plugin/errors: 0 host.k3d.internal. AAAA: plugin/rewrite: no next plugin found

So host.k3d.internal does not seem to be reachable inside server blocks.

Edit 2: I finally fixed my issue with the following ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns-custom
  namespace: kube-system
data:
  my-internal.domain.server: |
    my-internal.domain.com {
        log
        rewrite name my-internal.domain.com host.k3d.internal
        forward . 127.0.0.1
    }

msaunois-dzr avatar Jul 27 '22 09:07 msaunois-dzr

It seems like this has been addressed upstream at k3s (https://github.com/k3s-io/k3s/issues/7639). In my limited testing, it's working like it should!

rassie avatar Jul 26 '23 14:07 rassie