<p>The example is described here - <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/</a></p>
<p>The Service object for the wordpress-mysql is:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
  clusterIP: None
</code></pre>
<p>The headless services are documented here - <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#headless-services</a> The Service definition defines selectors, so I suppose <a href="https://kubernetes.io/docs/concepts/services-networking/service/#with-selectors" rel="nofollow noreferrer">the following passage</a> applies:</p>
<blockquote>
<p>For headless Services that define selectors, the endpoints controller
creates Endpoints records in the API, and modifies the DNS
configuration to return records (addresses) that point directly to the
Pods backing the Service</p>
</blockquote>
<p>I have followed the example on a 3 node managed k8s cluster in Azure:</p>
<pre><code>C:\work\k8s\mysql-wp-demo&gt; kubectl.exe get ep
NAME              ENDPOINTS          AGE
kubernetes        52.186.94.71:443   47h
wordpress         10.244.0.10:80     5h33m
wordpress-mysql   10.244.3.28:3306   5h33m
C:\work\k8s\mysql-wp-demo&gt; kubectl.exe get pods -o wide
NAME                               READY   STATUS    RESTARTS   AGE     IP            NODE                                NOMINATED NODE   READINESS GATES
wordpress-584f8d8666-rlbf5         1/1     Running   0          5h33m   10.244.0.10   aks-nodepool1-30294001-vmss000001   &lt;none&gt;           &lt;none&gt;
wordpress-mysql-55c74969cd-4l8d4   1/1     Running   0          5h33m   10.244.3.28   aks-nodepool1-30294001-vmss000003   &lt;none&gt;           &lt;none&gt;
C:\work\k8s\mysql-wp-demo&gt;
</code></pre>
<p>As far as I understand there is no difference from the endpoints perspective.</p>
<p>Can someone explain to me - what is the point of headless services in general and in this example in particular?</p>

<p>A regular service has a virtual <a href="https://kubernetes.io/docs/concepts/services-networking/service/#ips-and-vips" rel="nofollow noreferrer">Service IP</a> that exists as iptables or ipvs rules on each node. A new connection to this service IP is then routed with DNAT to one of the Pod endpoints, to support a form of load balancing across multiple pods.</p>
<p>A <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">headless service</a> (that isn't an <code>ExternalName</code>) will create DNS <code>A</code> records for any endpoints with matching labels or name. Connections will go directly to a single pod/endpoint without traversing the service rules.</p>
<p>A service with a type of <code>ExternalName</code> is just a DNS <code>CNAME</code> record in kubernetes DNS. These are headless by definition as they are names for an IP external to the cluster.</p>
<p>The linked myql deployment/service example is leading into StatefulSet's. This Deployment is basically a single pod statefulset. When you do move to a StatefulSet with multiple pods, you will mostly want to address individual members of the StatefulSet with a specific name (see <a href="https://stackoverflow.com/users/225016/mdaniel">mdaniel</a>s comment).</p>
<p>Another reason to set <code>clusterIP: None</code> is to lessen the load on iptables processing which slows down as the number of services (i.e. iptables rules) increases. Applications that don't need multiple pods, don't need the Service IP. Setting up a cluster to use IPVS alleviates the slow down issue somewhat.</p>
<p><a href="https://i.stack.imgur.com/713t5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/713t5.png" alt="service flow" /></a></p>
