Headless services with selector does not get endpoint

9/13/2016

on GKE I created some pods and a headless service. The headless service has a selector and I am expecting the endpoint to get the IP of the Pod that matches the selector.

However the endpoint remains empty

$ kubectl get pods -lservice=front-end
NAME                         READY     STATUS    RESTARTS   AGE
front-end-1567472915-tei91   1/1       Running   0          12m
$ kubectl get svc -lapp=sockshop
NAME        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
front-end   None         <none>                  11m
$ kubectl get endpoints -lapp=sockshop
NAME        ENDPOINTS   AGE
front-end   <none>      11m
$ more svc.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: sockshop
  name: front-end
spec:
  clusterIP: None
  ports: null
  selector:
    service: front-end

I would expect an endpoint to get the IP of the Pod so that the DNS registration works.

-- Sebastien Goasguen
kubernetes

1 Answer

9/15/2016

if ports is set to null the endpoint will not get populated.

You need to add a port (even a dummy one) for the endpoint to get populated with the PodIPs of the Pods that match the selector.

ports: - port: 1234 protocol: TCP targetPort: 1234

-- Sebastien Goasguen
Source: StackOverflow