<p>I declared two containers in minikube cluster, <code>elasticsearch</code> and <code>kibana</code>. <code>kibana</code> needs to access elasticsearch endpoint at 9200 port. I declared <code>elasticsearch</code> as <code>StatefulSet</code> and give a serviceName <code>elasticsearch</code>.</p>
<p>When I look at kibana log I can see this error:</p>
<pre><code>{&quot;type&quot;:&quot;log&quot;,&quot;@timestamp&quot;:&quot;2020-12-31T03:37:45Z&quot;,&quot;tags&quot;:[&quot;warning&quot;,&quot;elasticsearch&quot;,&quot;monitoring&quot;],&quot;pid&quot;:6,&quot;message&quot;:&quot;Unable to revive connection: http://elasticsearch:9200/&quot;}
{&quot;type&quot;:&quot;log&quot;,&quot;@timestamp&quot;:&quot;2020-12-31T03:37:45Z&quot;,&quot;tags&quot;:[&quot;warning&quot;,&quot;elasticsearch&quot;,&quot;monitoring&quot;],&quot;pid&quot;:6,&quot;message&quot;:&quot;No living connections&quot;}
</code></pre>
<p>it means kibana can't reach <code>elasticsearch</code> hostname. Is there anything wrong with my configuration?</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-cluster
spec:
  serviceName: elasticsearch-entrypoint 
  replicas: 1
  selector:
    matchLabels:
      name: elasticsearch
  template:
    metadata:
      labels:
        name: elasticsearch
    spec:
      containers:
        - name: elasticsearch
          image: elasticsearch:7.10.1
          ports:
            - containerPort: 9200
              name: rest
            - containerPort: 9300
              name: inter-node
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kibana
spec:
  replicas: 1
  selector:
    matchLabels:
      name: kibana
  template:
    metadata:
      labels:
        name: kibana
    spec:
      containers:
        - name: kibana
          image: kibana:7.10.1
          ports:
            - containerPort: 5601
          env:
            - name: ELASTICSEARCH_HOSTS
              value: http://es-cluster-0.elasticsearch-entrypoint.default.svc.local:9200
---
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-entrypoint
  namespace: default
spec:
  clusterIP: None
  selector:
    name: elasticsearch
  ports:
  - port: 9200
    name: rest
  - port: 9300
    name: inter-node
---
apiVersion: v1
kind: Service
metadata:
  name: kibana-entrypoint
  namespace: default
spec:
  selector:
    name: kibana
  ports:
  - port: 5601

</code></pre>

Joey Yi Zhao
<p>You need to create a headless governing service for your statefulSet:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-entrypoint
  namespace: default
spec:
  clusterIP: None
  selector:
    name: elasticsearch
  ports:
  - port: 9200
    name: rest
  - port: 9300
    name: inter-node

</code></pre>
<p>In your deployment of kibana env variable <code>ELASTICSEARCH_HOSTS</code> need to set <code>http://es-cluster-0.elasticsearch-entrypoint.default.svc.cluster.local:9200</code>.</p>
<p>The template is like <code>my_pod_name.my_Service_Name.my_Namespace.svc.cluster-domain.example</code> , but you can skip the cluster-domain.example part. Only <code>Service_Name.Namespace.svc</code> will work fine.</p>
<p>here is the full yaml</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-cluster
spec:
  serviceName:  elasticsearch-entrypoint
  replicas: 1
  selector:
    matchLabels:
      name: elasticsearch
  template:
    metadata:
      labels:
        name: elasticsearch
    spec:
      containers:
        - name: elasticsearch
          image: elasticsearch:7.10.1
          ports:
            - containerPort: 9200
              name: rest
            - containerPort: 9300
              name: inter-node
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kibana
spec:
  replicas: 1
  selector:
    matchLabels:
      name: kibana
  template:
    metadata:
      labels:
        name: kibana
    spec:
      containers:
        - name: kibana
          image: kibana:7.10.1
          ports:
            - containerPort: 5601
          env:
            - name: ELASTICSEARCH_HOSTS
              value: http://es-cluster-0.elasticsearch-entrypoint.default.svc.cluster.local:9200
---
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-entrypoint
  namespace: default
spec:
  clusterIP: None
  selector:
    name: elasticsearch
  ports:
  - port: 9200
    name: rest
  - port: 9300
    name: inter-node
---
apiVersion: v1
kind: Service
metadata:
  name: kibana-entrypoint
  namespace: default
spec:
  selector:
    name: kibana
  ports:
  - port: 5601

</code></pre>
<ul>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#a-aaaa-records" rel="nofollow noreferrer">Ref</a></li>
</ul>
