Search code examples
kubernetesdnsjvmminikubecoredns

Minikube's CoreDNS fails to resolve names from JVM


Our JVM services (based on Java SE 8/Scala/Finagle) have problems resolving DNS names. I have checked coredns deployment logs in kube-system namespace and found out that java.net.InetAddress.getAllByName() is querying for ANY record type.

If I check name resolution via nslookup I can confirm that ANY record type is not resolvable, but A or AAAA records are:

# kubectl exec -i -t dnsutils -- nslookup -type=a weather.mab.matjazmav.test
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   dev-proxy.default.svc.cluster.local
Address: 10.100.187.185

# kubectl exec -i -t dnsutils -- nslookup -type=any weather.mab.matjazmav.test
Server:         10.96.0.10
Address:        10.96.0.10#53

*** Can't find weather.mab.matjazmav.test: No answer

My question is, how can I make Minikube's CoreDNS respond to ANY query, or how can I force java.net.InetAddress to send A or AAAA query?

EDIT: It turned out that we used old NS provider that ships with Java SE 8 (sun.net.spi.nameservice.provider.1=dns,sun) see my answer for details.


Solution

  • I found two possible solutions:

    1. Use CoreDNS rewrite plugin

    Rewrite query types from ANY to A. Here is a link to the documentation: https://coredns.io/plugins/rewrite/

    2. Use default NS provider inside JVM

    This applies only if you run on Jave SE 8 or older. Java SE 9 removed this system property, read more here: https://www.oracle.com/java/technologies/javase/9-removed-features.html#JDK-8134577

    Java SE 8 ships with two NS providers default and dns,sun. default provider uses system's NS provider while dns,sun uses some old NS implementation.

    To use default NS provider simply set the following property:

    sun.net.spi.nameservice.provider.1=default
    

    Read more here: https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

    Also this is a nice read: https://medium.com/@maheshsenni/host-name-resolution-in-java-80301fea465a