How do I access external hosts from within my cluster?

11/13/2017

I have a container with a specialized application that needs to connect to hosts, via DNS lookup, outside of the Kubernetes cluster. When I run the container standalone in Docker, things work fine.

When I run the container using Kubernetes though, I'm getting "host not found" errors. If I run bash inside the container, and do a "ping myhost.mydomain.com ", it fail to resolve myhost.mydomain.com.

Reading through the Kubernetes pages, it appears all I need to do is this add this service:

apiVersion: v1 kind: Service metadata: name: myhost spec: type: ExternalName externalName: myhost.mydomain.com

But, this doesn't seem to work; the container still can't ping myhost or myhost.mydomain.com. Is there something else I need to add? Is there some way to have a "fallback" DNS so that any external hostname can be resolved? It doesn't seem like this should be this difficult...

Thanks, John

-- John Fisher
kubernetes

1 Answer

11/14/2017

Try to add dnsPolicy: ClusterFirstWithHostNet to the spec.

-- Velkan
Source: StackOverflow