Score:2

Kubernates CoreDNS direct a public url to a internal server

cn flag

I have an app running in Kubernetes clusters which is accessing to a public API URL for e.g. api.server123.com. The app is accessing it within its code itself

I want to resolve that public UZRL to an internal IP like how we can do it in /etc/host i.e. an entry like 1.2.3.4 api.server123.com where that IP belongs to one of our internal servers. This is for me to see the payload sent out and some internal checks.

Can I do this via the CoreDNS?

I did it like this but does not seems to work.

Corefile: |-
    .:53 {
        errors
        health
        kubernetes cluster.local. in-addr.arpa ip6.arpa {
            pods insecure
            upstream
            fallthrough in-addr.arpa ip6.arpa
        }
        hosts {
            1.2.3.4     api.server123.com
            fallthrough
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        reload
        loadbalance
    }

Is this the correct way to resolve a public URL to an internal IP within Kubernetes?

Score:0
tr flag

I recommend you to use forward plugin for Corefile configuration. According to Kubernetes.io:

forward: Any queries that are not within the cluster domain of Kubernetes will be forwarded to predefined resolvers (/etc/resolv.conf).

Useful examples you can find at coredns.io

Wytrzymały Wiktor avatar
it flag
Hello @Ruster and welcome to ServerFault! Please remember to [react to answers for your questions](https://stackoverflow.com/help/someone-answers). That way we know if the answers were helpful and other community members could also benefit from them. Try to [accept answer](https://stackoverflow.com/help/accepted-answer) that is the final solution for your issue, upvote answers that are helpful and comment on those which could be improved or require additional attention. Enjoy your stay!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.