-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not resolve hostname in Kubernetes #6099
Comments
I could nslookup |
Related to #2660 |
But we merged #2745 ? |
Ah, mh I guess that should have fixed this point, we didn't revert any of that by chance? @liuyang1204 Ruby and Python are for example able to resolve these as well? |
No, nothing changed. We use blocking |
Also happens on Docker Swarm, with the overlay network |
a strace of the |
@jhass I'm using Crystal 0.24.1 BTW. |
Additional information: I'm running the statically linked Crystal executable in Alpine docker image. Don't know this matters or not though. |
Can you try out require "socket"
p Socket::Addrinfo.resolve("some.service", 80, type: Socket::Type::STREAM)
p Socket::Addrinfo.resolve("some.service", "http", family: Socket::Family::INET6) Notes:
|
The first resolve throws an exception: No address found for some-service:80 over IP (Socket::Error)
from usr/share/crystal/src/socket/addrinfo.cr:0:33 in '???'
from usr/share/crystal/src/http/server/request_processor.cr:255:3 in 'process'
from usr/share/crystal/src/fiber.cr:255:3 in '???'
from ??? The second resolve doesn't compile: Error in app.cr:9: instantiating 'Socket::Addrinfo:Class#resolve(String, String)'
p Socket::Addrinfo.resolve("some.service", "http", family: Socket::Family::INET6)
^~~~~~~
in /usr/local/Cellar/crystal-lang/0.24.2_1/src/socket/addrinfo.cr:28: can't restrict Nil to Type
def self.resolve(domain, service, family : Family? = nil, type : Type = nil, protocol : Protocol = Protocol::IP, timeout = nil) : Array(Addrinfo) |
Dockerfile
app.cr require "socket"
require "http/server"
server = HTTP::Server.new("0.0.0.0", 8080) do |context|
context.response.content_type = "text/plain"
p Socket::Addrinfo.resolve("some-service", 80, type: Socket::Type::STREAM)
end
puts "Listening on http://0.0.0.0:8080"
server.listen |
Confirmed that the app can resolve the hostname without static compile
But then I miss the small image. |
I don't understand how a static build is working on glibc at all to be honest. I would guess it's issues with the loadable nsswitch stuff. Not really a bug on crystal's side either way. You'll have to just forgo the static build, or make a static build on alpine (we should really provide good official tooling for doing this in docker) |
So, the problem is using a static glibc then run it in a non glibc environment, where it probably can't find some expected dynamic libraries (see link warnings) or some configuration. There is sadly nothing we can do, here... A solution could be to build a dynamic executable under alpine itself (we have issues with musl+static), pulling the crystal tarball (it's statically linked) and installing packaged dependencies (pcre, libgc) on both build/run containers. |
I didn't see any warning, and the application runs perfectly except the hostname problem. Alpine is not what I want, I just want to use a tiny base image to run my Crystal app. Any guides would be appreciated, for example: If I make a static build using Anyway really appreciate the fast responses and kind explanation. |
glibc is known for still dynamically load libraries at runtime when built statically. It's usually fine but sometimes it's not. I suspect getaddrinfo is one of them, it may need to load some nsswitch libs but they're nowhere to be found in a musl-libc distribution. I'm afraid I can't help much otherwise. Building and running under the same base image seems like a sound advice, thought. Crystal is now officially packaged on alpine for example. |
Closing, since the issue is related to glibc being statically compiled. |
@liuyang1204 Did you try this: https://manas.tech/blog/2017/04/03/shipping-crystal-apps-in-a-small-docker-image.html ? |
@faustinoaq Thanks, yes I've checked it but thought the solution is a little bit fat. (The list deps script and copying setting) So I tried static compile approach. I have some updates: The build with static flag actually outputs some warnings:
And I tried to use |
Using the solution in https://manas.tech/blog/2017/04/03/shipping-crystal-apps-in-a-small-docker-image.html
doesn't solve the issue. I guess I met the same problem with this comment and need to copy those 2 files. But I'm quite happy with busybox now. |
Just adding for history's sake. Was able to get alpine image to work:
|
@kalinon There are official Alpine docker images now: https://crystal-lang.org/2020/02/02/alpine-based-docker-images.html. |
@Blacksmoke16 should official alpine images resolve this issue ? |
@benbonnet Dunno, would have to try it out. |
@Blacksmoke16 currently having the following :
and still getting what's described by @LeonLiuY here ( Using a |
@benbonnet Can you not just use the alpine image mentioned earlier? Something like: FROM crystallang/crystal:0.35.1-alpine as build
COPY shard.lock /app/shard.lock
COPY shard.yml /app/shard.yml
WORKDIR /app
RUN shards install --production
COPY src/ /app/src/
RUN shards build --release --production --no-debug --static
RUN strip ./bin/svc
FROM alpine:3.12
COPY --from=build /app/bin /
EXPOSE 3000
ENV KEMAL_ENV=production
CMD ["./svc"] The problem is you can't statically link on Ubuntu which is what |
The TCP client can not connect to services in Kubernetes using the service hostname.
For example
http://some-service
ormysql://root@some-service:3306/db
The error is
No address found for some-service:80 over TCP
Changing the hostname
some-service
to the cluster IP addr in Kubernetes makes the connections successful.This happens both to HTTP clients and DB clients.
The text was updated successfully, but these errors were encountered: