Reputation: 48
I'm using google container engine and I can create pods and services in my cluster. But when I try to use the DNS feature (skydns) to lookup my services nothing is being found. If I log in to the non-master node, I can see the DNS container and can use 'host' command to do DNS lookup (installed with apt-get). But I can't find my service by it's name. It associates kubernetes.local with the IP of the service. Actually it associates kubernetes.local with the IP of every one of my services (I have 9). But it does not associate the service name "my-service-name".
Anyone know the trick to get this to work? Either creating the service isn't causing skydns to create the DNS entry (maybe there is some magic to make it work)...or I'm just completely clueless (less magical, perhaps more likely).
I don't know which.
b
Upvotes: 2
Views: 1525
Reputation: 13377
There's a little bit of magic involved that's intended to make DNS in Kubernetes more convenient from within a pod. Let me try to explain.
The way that the DNS names are constructed within Kubernetes is <service-name>.<namespace>.kubernetes.local
. This is why kubernetes.local
is resolving from on your node, but my-service-name
isn't. Assuming your service is defined in the default namespace (it will be unless you explicitly created it in a different namespace), you should be able to resolve it at my-service-name.default.kubernetes.local
.
The docs around DNS assume that you care about how to resolve service names from within a pod rather than directly on the host. Within your pod, DNS should be set up to first search for names you specify relative to default.kubernetes.local
and kubernetes.local
, meaning that from within any pod in the cluster that isn't kube-dns (it's handled specially) you should be able to resolve your service using either my-service-name
or my-service-name.default.kubernetes.local
.
If you want to try it out, attach to one of your cluster's fluentd pods using docker exec and try looking up your service from within the container.
Note that the namespace changed from kubernetes.local
to cluster.local
between versions 0.17.0 and 0.18.0, so check your cluster's version (using kubectl version
) if your first attempt doesn't work.
Upvotes: 4