<p>I have a k8 setup that looks like this</p>
<p><code>ingress -&gt; headless service (k8 service with clusterIp: none) -&gt; statefulsets ( 2pods)</code></p>
<p>Fqdn looks like this:</p>
<pre><code>nslookup my-service
Server:         100.4.0.10
Address:        100.4.0.10#53

Name:   my-service.my-namespace.svc.cluster.local
Address: 100.2.2.8
Name:   my-service.my-namespace.svc.cluster.local
Address: 100.1.4.2
</code></pre>
<p>I am trying to reach one of the pod directly via the service using the following fqdn but not able to do so.</p>
<pre><code>curl -I my-pod-0.my-service.my-namespace.svc.cluster.local:8222
curl: (6) Could not resolve host: my-pod-0.my-service.my-namespace.svc.cluster.local
</code></pre>
<p>If I try to hit the service directly then it works correctly (as a loadbalancer)</p>
<pre><code>curl -I my-service.my-namespace.svc.cluster.local:8222
HTTP/1.1 200 OK
Date: Sat, 31 Jul 2021 21:24:42 GMT
Content-Length: 656
</code></pre>
<p>If I try to hit the pod directly using it's cluster ip,  it also works fine</p>
<pre><code>curl -I 100.2.2.8:8222
HTTP/1.1 200 OK
Date: Sat, 31 Jul 2021 21:29:22 GMT
Content-Length: 656
Content-Type: text/html; charset=utf-8
</code></pre>
<p>But my use case requires me to be able to hit the statefulset pod using fqdn i.e <code>my-pod-0.my-service.my-namespace.svc.cluster.local</code> . What am I missing here?</p>

java_doctor_101
<p>example statefulset called <code>foo</code> with image <code>nginx</code>:</p>
<pre><code>k get statefulsets.apps
NAME   READY   AGE
foo    3/3     8m55s
</code></pre>
<p>This stateful set created following pods(<code>foo-0,foo-1,foo-2</code>):</p>
<pre><code>k get pod -o wide
NAME      READY   STATUS    RESTARTS   AGE     IP             NODE        NOMINATED NODE   READINESS GATES
busybox   1/1     Running   1          3h47m   10.1.198.71    ps-master   &lt;none&gt;           &lt;none&gt;
foo-0     1/1     Running   0          12m     10.1.198.121   ps-master   &lt;none&gt;           &lt;none&gt;
foo-1     1/1     Running   0          12m     10.1.198.77    ps-master   &lt;none&gt;           &lt;none&gt;
foo-2     1/1     Running   0          12m     10.1.198.111   ps-master   &lt;none&gt;           &lt;none&gt;
</code></pre>
<p>Now create a headless service(<code>clusterIP is none</code>) as follow:(make sure to use correct selector same as your statefulset)</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: foo
spec:
  type: ClusterIP
  clusterIP: None
  ports:
  - port: 80
    name: web
  selector:
    app: foo
</code></pre>
<p>Now, do <code>nslookup</code> to see the <code>dns</code> resolution working for the service.(Optional step)</p>
<pre><code>k exec -it busybox -- nslookup nginx.default.svc.cluster.local
Server:    10.152.183.10
Address 1: 10.152.183.10 kube-dns.kube-system.svc.cluster.local

Name:      nginx.default.svc.cluster.local
Address 1: 10.1.198.77 foo-1.nginx.default.svc.cluster.local
Address 2: 10.1.198.111 foo-2.nginx.default.svc.cluster.local
Address 3: 10.1.198.121 foo-0.nginx.default.svc.cluster.local
</code></pre>
<p>Now validate that, individual resolution per-pod is working:</p>
<pre><code>k exec -it busybox -- nslookup foo-1.nginx.default.svc.cluster.local
Server:    10.152.183.10
Address 1: 10.152.183.10 kube-dns.kube-system.svc.cluster.local

Name:      foo-1.nginx.default.svc.cluster.local
Address 1: 10.1.198.77 foo-1.nginx.default.svc.cluster.local
</code></pre>
<p>More info: <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id" rel="nofollow noreferrer">Here</a></p>
<p>Note: In this case OP had incorrect mapping of <code>headless</code> service and the <code>statefulset</code>, this can be verified with below command:</p>
<pre><code>k get statefulsets.apps foo -o jsonpath=&quot;{.spec.serviceName}{'\n'}&quot;
nignx
</code></pre>
<p>Ensure that, the mapping.</p>
