Kubernetes headless service A Record round robin

8/25/2016

I'm trying to create two kubernetes services, one which is a loadbalancer with a cluster IP, and another which is a headless (no cluster IP), but instead returns an A record round robin collection of the pod ip addresses (as it should do, according to http://kubernetes.io/docs/user-guide/services/#headless-services).

I need to do this because I need a dynamic collection of pod ip's in order to do auto clustering and service discovery.

My services look like this:

apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  labels:
    app: rabbitmq
    tier: messaging
spec:
  ports:
  - name: amqp
    port: 5672
    targetPort: 5672
  selector:
    app: rabbitmq
    tier: messaging
---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-cluster
  labels:
    app: rabbitmq
    tier: messaging
spec:
  clusterIP: None
  ports:
  - name: amqp
    port: 5672
    targetPort: 5672
  selector:
    app: rabbitmq
    tier: messaging

With these two services, i get the following:

$ kubectl get services
NAME               CLUSTER-IP      EXTERNAL-IP       PORT(S)     AGE
rabbitmq           10.23.255.174   <none>            5672/TCP    7m
rabbitmq-cluster   None            <none>            5672/TCP    7m

And DNS (from another pod) for the cluster IP works:

[root@gateway-3738159135-a7wp9 app]# nslookup rabbitmq.td-integration
Server:     10.23.240.10
Address:        10.23.240.10#53

Name:   rabbitmq.td-integration.svc.cluster.local
Address: 10.23.255.174

However, the dns for the 'headless' service, doesn't return:

[root@gateway-3738159135-a7wp9 app]# nslookup rabbitmq-cluster.td-integration
Server:     10.23.240.10
Address:        10.23.240.10#53

** server can't find rabbitmq-cluster.td-integration: NXDOMAIN
-- Stono
dns
google-kubernetes-engine
kubernetes
skydns

1 Answer

8/26/2016

It seems like there is no pod matching these labels within your cluster, therefore the DNS query doesn't return anything. This is expected.

Start the corresponding pods and you should see a list of A records.

Please be aware that these A records are not shuffled as far as I know, so your clients are expected to consume the DNS answer and perform their own round robin.

-- Antoine Cotten
Source: StackOverflow