2

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?

Dave M
  • 4,494
  • 21
  • 30
  • 30
Ruster
  • 21
  • 2

1 Answers1

0

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

  • 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! – Wytrzymały Wiktor Sep 01 '21 at 08:30