0

I'm trying to resolve mx records in a kubernetes pod. The dnsjava library works when tested on mac and ubuntu outside of a container but returns an empty array once deployed.

What needs to be available in k8s or the docker image for this to work?

See https://github.com/dnsjava/dnsjava

EDIT 1

  Record[] records;
  try {
    records = new Lookup(mailDomain, Type.MX).run();
  } catch (TextParseException e) {
    throw new IllegalStateException(e);
  }
  if (records != null && records.length > 0) {
    for (final Record record : records) {
      MXRecord mx = (MXRecord) record;
      //do something with mx...
    }
  } else {
    log.warn("Failed to determine MX record for {}", mailDomain);
  }

The log.warn is always executed in K8s. The docker image is openjdk:11-jdk-slim i.e. it's Debian. I just tested on Debian outside of Docker and it worked as well.

zcourts
  • 4,863
  • 6
  • 49
  • 74
  • If it works in ubuntu did you try in ubuntu container? Could you elaborate a bit how you are testing it and what output you received? – PjoterS Aug 21 '20 at 07:52
  • I've edited to provide more info. There is no output, either `run` is returning null or an empty array. I'm testing by calling an API which the app provides which then calls the above code. I call the same API in and outside of the container – zcourts Aug 21 '20 at 08:48

1 Answers1

0

In the end I couldn't get dnsjava to work in docker/k8s. I used JNDI directly, following https://stackoverflow.com/a/16448180/400048 this works without any issues exactly as given in that answer.

zcourts
  • 4,863
  • 6
  • 49
  • 74