<p>From the document, it can be found there is a <code>Stable Network ID</code> feature to use for <code>Pod NDS</code>:</p>
<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id</a></p>
<p>I tried to do</p>
<h1>service.yaml</h1>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: logstash
  name: logstash
spec:
  selector:
    app: logstash
  ports:
    - name: &quot;5044&quot;
      port: 5044
      targetPort: 5044
</code></pre>
<h1>statefulset.yaml</h1>
<pre><code>---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: logstash
spec:
  serviceName: &quot;logstash&quot;
  selector:
    matchLabels:
      app: logstash
  updateStrategy:
    type: RollingUpdate
  replicas: 2
  template:
    metadata:
      labels:
        app: logstash
    spec:
      containers:
      - name: logstash
        image: docker.elastic.co/logstash/logstash:7.10.0
        resources:
          limits:
            memory: 2Gi
        ports:
          - containerPort: 5044
        volumeMounts:
          - name: config-volume
            mountPath: /usr/share/logstash/config
          - name: logstash-pipeline-volume
            mountPath: /usr/share/logstash/pipeline
        command: [&quot;/bin/sh&quot;,&quot;-c&quot;]
        args:
          - bin/logstash -f /usr/share/logstash/pipeline/logstash.conf;
      volumes:
        - name: config-volume
          configMap:
            name: configmap-logstash
            items:
              - key: logstash.yml
                path: logstash.yml
        - name: logstash-pipeline-volume
          configMap:
            name: configmap-logstash
            items:
              - key: logstash.conf
                path: logstash.conf
</code></pre>
<h1>configmap.yaml</h1>
<pre><code>---
apiVersion: v1
kind: ConfigMap
metadata:
  name: configmap-filebeat
  labels:
    k8s-app: filebeat
data:
  filebeat.yml: |-
    filebeat.inputs:
      - type: log
        enabled: true
        paths:
          - /var/lib/nginx/access.json

    output.logstash:
      hosts: [&quot;logstash-0.logstash.default.svc.cluster.local:5044&quot;, &quot;logstash-1.logstash.default.svc.cluster.local:5044&quot;]
      loadbalance: true
</code></pre>
<p>Filebeat is deploying into a daemonset use this configuration.</p>
<p>It can't work. From the filebeat's log got:</p>
<pre><code>2020-12-22T02:10:34.395Z    WARN    [transport] transport/tcp.go:52 DNS lookup failure &quot;logstash-1.logstash.default.svc.cluster.local&quot;: lookup logstash-1.logstash.default.svc.cluster.local: no such host
</code></pre>
<p>If use this config, it can work:</p>
<pre><code>    output.logstash:
      hosts: [&quot;logstash.default.svc.cluster.local:5044&quot;]
</code></pre>
<p>Why it caused <code>DNS lookup failure</code> issue when use <code>Pod DNS</code> format? Is there any more conditions to use this feature? Then how to do?</p>

iooi
<p>Also note from the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id" rel="nofollow noreferrer">StatefulSet documentation</a>:</p>
<blockquote>
<p>As mentioned in the limitations section, you are responsible for creating the Headless Service responsible for the network identity of the pods.</p>
</blockquote>
<p>So you are resposible for creating <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">Headless Services</a> for the pods, e.g. <code>logstash-0</code> and <code>logstash-1</code>.</p>
