Search code examples
kubernetesurl-rewritingcoredns

Kubernetes CoreDNS rewrite CNAME record rules for specific namespace


For my project I need to overwrite CNAME DNS records with CoreDNS for internal cluster DNS resolution. I can do this globally for a cluster like this:

apiVersion: v1
        data:
        Corefile: |
            # Add your CoreDNS customizations as import files.
            # Refer to https://cloud.ibm.com/docs/containers?topic=containers-cluster_dns for details.
            .:53 {
                rewrite name test.example.com example.namespace1.svc.cluster.local
                ...
            }
...

So in the whole cluster all requests to test.example.com will be sended to service: example.namespace1.svc.cluster.local.

Is it possible to define rewrite rule only for specific namespace? For example I want only namespace1 to have this rewrite rule in place.

Thank you!


Solution

  • No it's not possible to have DNS per namespace by modifying the configMap of core DNS because coreDNS is a cluster wide DNS . If your use case is to expose services via hostname then you can explore ingress