Does the Google Container Engine support DNS based service discovery?

9/30/2015

From the kubernetes docs I see that there is a DNS based service discovery mechanism. Does Google Container Engine support this. If so, what's the format of DNS name to discover a service running inside Container Engine. I couldn't find the relevant information in the Container Engine docs.

-- chitti
google-kubernetes-engine
kubernetes

2 Answers

11/11/2015

The DNS name for services is as follow: {service-name}.{namespace}.svc.cluster.local.

Assuming you configured kubectl to work with your cluster you should be able to get your service and namespace details by the following the steps below.

Get your namespace

$ kubectl get namespaces
NAME          LABELS    STATUS
default       <none>    Active
kube-system   <none>    Active

You should ignore the kube-system entry, because that is for the cluster itself. All other entries are your namespaces. By default there will be one extra namespace called default.

Get your services

$ kubectl get services
NAME                  LABELS                                                    SELECTOR                   IP(S)            PORT(S)
broker-partition0     name=broker-partition0,type=broker                        name=broker-partition0     10.203.248.95    5050/TCP
broker-partition1     name=broker-partition1,type=broker                        name=broker-partition1     10.203.249.91    5050/TCP
kubernetes            component=apiserver,provider=kubernetes                   <none>                     10.203.240.1     443/TCP
service-frontend      name=service-frontend,service=frontend                    name=service-frontend      10.203.246.16    80/TCP
                                                                                                           104.155.61.198   
service-membership0   name=service-membership0,partition=0,service=membership   name=service-membership0   10.203.246.242   80/TCP
service-membership1   name=service-membership1,partition=1,service=membership   name=service-membership1   10.203.248.211   80/TCP

This command lists all the services available in your cluster. So for example, if I want to get the IP address of the service-frontend I can use the following DNS: service-frontend.default.svc.cluster.local.

Verify DNS with busybox pod

You can create a busybox pod and use that pod to execute nslookup command to query the DNS server.

$ kubectl create -f - << EOF
apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: default
spec:
  containers:
  - image: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: busybox
  restartPolicy: Always
EOF

Now you can do an nslookup from the pod in your cluster.

$ kubectl exec busybox -- nslookup broker-partition0.default.svc.cluster.local
Server:    10.203.240.10 
Address 1: 10.203.240.10

Name:      service-frontend.default.svc.cluster.local
Address 1: 10.203.246.16

Here you see that the Addres 1 entry is the IP of the service-frontend service, the same as the IP address listed by the kubectl get services.

-- pjvds
Source: StackOverflow

10/3/2015

It should work the same way as mentioned in the doc you linked to. Have you tried that? (i.e. "my-service.my-ns")

-- DavidO
Source: StackOverflow