<p>I have the following YAML file -</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    name: mariadb
  name: mariadb
spec:
  ports:
    - port: 3306
  selector:
    name: mariadb
</code></pre>

<p>When this service is created, a ClusterIP is automatically set.
My stateful set 'mariadb' is exposed using this service.
But if I login to another pod on Kubernetes, I cannot ping this pod using</p>

<pre><code>ping mariadb-0.mariadb.[namespace].svc.cluster.local
</code></pre>

<p>It also does not work if the ServiceType is set to 'NodePort'.</p>

<p>If I update the service to </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    name: mariadb
  name: mariadb
spec:
  ports:
    - port: 3306
  clusterIP: None
  selector:
    name: mariadb
</code></pre>

<p>When I login to another pod on Kubernetes, I can ping this pod using</p>

<pre><code>ping mariadb-0.mariadb.[namespace].svc.cluster.local
</code></pre>

<p>Is there any reason why this internal url is not accessible when the ClusterIP is set?</p>

jdoe
<p>The key is 'clusterIP: None'. </p>

<p>If clusterIP is not set, k8s will allocate one for the service automatically, also the kube-dns will set a domain name for the service, named mariadb.[namespace].svc.cluster.local, that's your first case. </p>

<p>While if clusterIP is set to 'None', that means k8s doesn't allocate a ip for the service, in this case, kube-dns will set a domain name for every endpoints that the service points to, in your second case, it's mariadb-0.mariadb.[namespace].svc.cluster.local. </p>

<p>Also you can set clusterIP to a ip address, in that case, it's the same as your first case.</p>

<p>That's why you can ping mariadb-0.mariadb.[namespace].svc.cluster.local in your second case, while can't in your first case.</p>
