<p>Learning Kubernetes by setting up two pods, each running an elastic-search and a kibana container respectively.</p>
<p>My configuration file is able to setup both pods as well as create two services to access these applications on host machine's web browser.</p>
<p>Issue is that i don't know how to make Kibana container communicate with ES application/pod.</p>
<p>Earlier while learning Docker i crafted a docker-compose app configuration and now basically trying to do the same using Kubernetes ( docker-compose config pasted below ) .</p>
<p>Came across a blog that suggested using <code>Deployment</code> instead of <code>Pod</code>. Again not sure how would one make Kibana talk to ES</p>
<p><strong>Kubernetes configuation yaml:</strong></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: pod-elasticsearch
  labels:
      app: myapp
spec:
  hostname: &quot;es01-docker-local&quot;

  containers:
    - name: myelasticsearch-container
      image: myelasticsearch
      imagePullPolicy: Never
      volumeMounts:
        - name: my-volume
          mountPath: /home/newuser

  volumes:
    - name: my-volume
      emptyDir: {}

---

apiVersion: v1
kind: Service

metadata:
    name: myelasticsearch-service
spec:
    type: NodePort
    ports:
        - targetPort: 9200
          port: 9200
          nodePort: 30015
    selector:
        app: myapp

---

apiVersion: v1
kind: Pod
metadata:
  name: pod-kibana
  labels:
      app: myapp
spec:
  containers:
    - name: mykibana-container
      image: mykibana
      imagePullPolicy: Never
      volumeMounts:
        - name: my-volume
          mountPath: /home/newuser
  volumes:
    - name: my-volume
      emptyDir: {}

---

apiVersion: v1
kind: Service
metadata:
    name: mykibana-service
spec:
    type: NodePort
    ports:
        - targetPort: 5601
          port: 5601
          nodePort: 30016
    selector:
        app: myapp
</code></pre>
<p>For reference below is the docker-compose that i am trying to replicate on Kubernetes</p>
<pre><code>version: &quot;2.2&quot;

services:

  elasticsearch:
    image: myelasticsearch
    container_name: myelasticsearch-container
    restart: always
    hostname: 'es01.docker.local'
    ports:
      - '9200:9200'
      - '9300:9300'
    volumes:
      - myVolume:/home/newuser/
    environment:
      - discovery.type=single-node


  kibana:
    depends_on:
      - elasticsearch
    image: mykibana
    container_name: mykibana-container
    restart: always
    ports:
      - '5601:5601'
    volumes:
      - myVolume:/home/newuser/
    environment:
      ELASTICSEARCH_URL: http://es01:9200
      ELASTICSEARCH_HOSTS: http://es01:9200
volumes:
  myVolume:

networks:
  myNetwork:
</code></pre>
<p>ES Pod description:</p>
<pre><code>% kubectl describe pod/pod-elasticsearch
Name:         pod-elasticsearch
Namespace:    default
Priority:     0
Node:         docker-desktop/192.168.65.3
Start Time:   Sun, 10 Jan 2021 23:06:18 -0800
Labels:       app=myapp
Annotations:  &lt;none&gt;
Status:       Running
IP:           10.x.0.yy
IPs:
  IP:  10.x.0.yy
</code></pre>

coredump
<p>If you want to deploy Elasticsearch and Kibana in Kubernetes the usual way then you have to take care of some core Elasticsearch cluster configuration like:</p>
<ul>
<li>cluster.initial_master_nodes [7.0] Added in 7.0.</li>
<li>network.host</li>
<li>network.publish_host</li>
</ul>
<p>Also you would have to carefully setup the network.host so that even after accidental pod restarts the network.host remains the same.</p>
<p>While deploying Kibana you need provide Elasticsearch service and also manually configure the SSL certificates if Elasticsearch has SSL enabled.</p>
<p>So to install Elastic Stack on Kubernetes then you should probably prefer
<a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/index.html" rel="nofollow noreferrer">Elastic Cloud on Kubernetes (ECK)</a>. The documentation provided by Elastic is easy to understand.</p>
<p><a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/index.html" rel="nofollow noreferrer">Elastic Cloud on Kubernetes (ECK)</a> uses <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/operator/" rel="nofollow noreferrer">Kubernetes Operators</a> to make installation easier and it automatically takes care of core <a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-reserved-settings.html" rel="nofollow noreferrer">cluster configuration</a>.</p>
<p>ECK installation will create a default user called <strong>&quot;elastic&quot;</strong> and you can retrieve its password from secrets. It also creates self-signed certificates which can be found in secrets.</p>
<p>For deploying Kibana you can just provide &quot;elasticsearchRef&quot; in your YAML file and it will automatically configure the Elasticsearch endpoints. You can use the default <strong>&quot;elastic&quot;</strong> user to login to Kibana.</p>
