amphp / dns

Async DNS resolution for PHP based on Amp.
https://amphp.org/dns
MIT License
157 stars 32 forks source link

DNS resolution not working on Kubernetes #82

Closed MassiAtHG closed 5 years ago

MassiAtHG commented 5 years ago

Basic resolving code works with containers set up using 'docker compose', but it does not when the containers run in a 'k8s' setup. Example code:

<?php
declare (strict_types = 1);

use \Amp\Loop;
use \Amp\Dns\Record;

require __DIR__ . '/vendor/autoload.php';

sleep(5);

Loop::run(function () {
    $records = yield \Amp\Dns\resolve('eventstore', Record::A);
    var_dump($records);
});

The error generated is the following:

Fatal error: Uncaught Amp\Dns\NoRecordException: No records returned for 'eventstore' (DNAME) in /app/vendor/amphp/dns/lib/Rfc1035StubResolver.php:317
Stack trace:
#0 [internal function]: Amp\Dns\Rfc1035StubResolver->Amp\Dns\{closure}()
#1 /app/vendor/amphp/amp/lib/Coroutine.php(76): Generator->send(Object(LibDNS\Messages\Message))
#2 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(130): Amp\Coroutine->Amp\{closure}(NULL, Object(LibDNS\Messages\Message))
#3 /app/vendor/amphp/amp/lib/Coroutine.php(81): Amp\Coroutine->resolve(Object(LibDNS\Messages\Message))
#4 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(43): Amp\Coroutine->Amp\{closure}(NULL, Object(LibDNS\Messages\Message))
#5 /app/vendor/amphp/amp/lib/Internal/PrivatePromise.php(23): class@anonymous->onResolve(Object(Closure))
#6 /app/vendor/amphp/amp/lib/Internal/Placeholder.php(125): Amp\Internal\PrivatePromise->onResolve(Object(Closure))
#7 /app/vendor/amphp/amp/lib/Deferred.php(45): class@anonymous->resolve(Object(Amp\Internal\PrivatePromise))
#8 /app/vendo in /app/vendor/amphp/dns/lib/Rfc1035StubResolver.php on line 317

Attached an archive used to verify the bug using 'minikube' (locally) and 'kops' (AWS). DNSTest.zip

MassiAtHG commented 5 years ago

An additional piece of info, the content of the 'resolve.conf' file on the AWS setup:

nameserver 100.64.0.10
search default.svc.cluster.local svc.cluster.local cluster.local eu-west-2.compute.internal
options ndots:5
kelunik commented 5 years ago

I guess the DNS is resolved via the search configuration? In that case, try eventstore.default.svc.cluster.local etc. and see whether that works.

MassiAtHG commented 5 years ago

Your suggestion seems to works correctly. Thank you very much.

kelunik commented 5 years ago

If you want direct support, please add a :+1: to #47.