Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Google Container Engine support DNS based service discovery?

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.

like image 752
chitti Avatar asked Sep 30 '15 09:09

chitti


People also ask

Does Kubernetes Support Service Discovery?

The services model in Kubernetes provides the most basic, but most important, aspect of microservices: discovery.

What type of service is Google Kubernetes engine?

Google Kubernetes Engine (GKE) provides a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. The GKE environment consists of multiple machines (specifically, Compute Engine instances) grouped together to form a cluster.

What is service discovery in GCP?

Service discovery helps application teams by: Reducing the amount of per-environment configuration. Decoupling client and server applications. Allowing applications to be portable to new environments.

How does Kubernetes service DNS work?

Kubernetes DNS schedules a DNS Pod and Service on the cluster, and configures the kubelets to tell individual containers to use the DNS Service's IP to resolve DNS names. Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name.


2 Answers

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.

like image 152
pjvds Avatar answered Oct 17 '22 19:10

pjvds


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

like image 45
DavidO Avatar answered Oct 17 '22 17:10

DavidO