Does Google Container Engine support DNS-based service discovery?

From the kubernetes docs, I see that there is a DNS discovery service mechanism. Does Google Container Engine support this. If so, what format of the DNS name does the service running inside the Container Engine detect? I could not find the relevant information in the container documents.

+6
source share
2 answers

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

Assuming you have configured kubectl to work with your cluster, you can get information about your service and namespace by following these steps.

Get namespace

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

You should ignore the kube-system entry because this is for the cluster itself. All other entries are namespaces . By default, another default namespace will be added.

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. For example, if I want to get the IP address of service-frontend , I can use the following DNS: service-frontend.default.svc.cluster.local .

Check DNS with busybox module

You can create a busybox module and use this module to execute the 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 nslookup from a block 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 address of the service-frontend , the same as the IP address specified in kubectl get services .

+6
source

It should work the same way as indicated in the document to which you are attached. Have you tried this? (ie. "my-service.my-ns")

+1
source

All Articles