<p>Created a headless service:</p>

<p>myapp-service-headless.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: myapp-service-headless
spec:
  ports:
    - port: 8000
  selector:
    app: myapp
  clusterIP: None
</code></pre>

<p>After create it to Kubernetes cluster, check its service status:</p>

<pre><code>$ kubectl create -f myapp-service-headless.yaml
$ kubectl describe service myapp-service-headless
Name:              myapp-service-headless
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       &lt;none&gt;
Selector:          app=myapp
Type:              ClusterIP
IP:                None
Port:              &lt;unset&gt;  8000/TCP
TargetPort:        8000/TCP
Endpoints:         172.17.0.11:8000,172.17.0.9:8000
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>Try to connect <code>172.17.0.11:8000</code> or <code>172.17.0.9:8000</code>, pending and no result.</p>

<p>Here using <code>kube-dns</code>: <code>myapp-service-headless.default.svc.cluster.local</code> in the application. Now it's in the container of pods.</p>

<p>So how to connect to these applications from other application via API? Which IP can been used?</p>

<p>Did you expose your container port inside your Endpoint (Pod)? </p>

<p>From what i knew, the headless service can be used to generate entries in kube-dns based on how you configure the Service, as discussed <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#a-records-and-hostname-based-on-pods-hostname-and-subdomain-fields" rel="nofollow noreferrer">in this doc</a>.</p>

<p>However, you can create another Service with <code>type: NodePort</code> that selects your backend Pods, and expose them on a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types" rel="nofollow noreferrer">NodePort/LB</a>.</p>
