Kubernetes + ELK : Connecting kibana to elasticsearch service

3/9/2019

I have Elasticsearch POD + SERVICE, and Kibana POD + SERVICE. I'm trying to connect my Kibana POD to Elasticsearch service, but I get connection errors.

This is my yaml of Kibaba POD:

apiVersion: v1
kind: Pod
metadata:
  name: kibana
  labels:
    app: kibana
spec:
  ports:
  containers:
  - name: kibana
    image: kibana:6.6.1
    command: ["/bin/sh"]
    args: ["-c", "bin/kibana --elasticsearch.url='elasticsearch-service:9200'"]

I get the following errors:

 FATAL  ValidationError: child "elasticsearch" fails because [child "hosts" fails because [single value of "hosts" fails because ["hosts" must be a valid uri with a scheme matching the http|https pattern]]]

From what I understand, I get error because the elasticsearch.url, doesn't start with http/https. So I tried to run args: ["-c", "bin/kibana --elasticsearch.url='http://elasticsearch-service:9200'"], but I get also connection errors (I think because service is not meant to be pointed with http/https).

This is the yaml of elasticsearch service (which works well):

apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-service
spec:
  ports:
  - port: 9200
    name: serving
    protocol: TCP
  - port: 9300
    name: node2node
    protocol: TCP
  selector:
    app: elasticsearch

With other PODs I could connect with elasticsearch-service:9200, but Kibana demends http/https. How can I make them connect?

-- Yagel
elasticsearch
kibana
kubernetes

4 Answers

3/9/2019

From the official documentation docs:

the docker-compose version is:

version: '2'
services:
  kibana:
    image: docker.elastic.co/kibana/kibana:6.6.1
    environment:
      SERVER_NAME: kibana.example.org
      ELASTICSEARCH_HOSTS: http://elasticsearch.example.org

You just convert it to kubernetes service either manually or using kompose tool and run it.

Or you can try to plugin the env variable into your existing file and remove the elasticsearch url option from ur command.

ELASTICSEARCH_HOSTS: http://elasticsearch.example.org

OR If you just name your elasticsearch service as elasticsearch , it should work without passing anything because the default value is:

http://elasticsearch:9200

example with your existing service name:

apiVersion: v1
kind: Pod
metadata:
  name: kibana
  labels:
    app: kibana
spec:
  ports:
  containers:
  - name: kibana
    image: docker.elastic.co/kibana/kibana:6.6.1
    env:
    - name: ELASTICSEARCH_HOSTS
      value: "http://elasticsearch-service:9200"
-- Ijaz Ahmad Khan
Source: StackOverflow

3/9/2019

Can you hit elasticsearch service from Kibana pod. Remove single quite around elasticsearch service. It is not required.

-- P Ekambaram
Source: StackOverflow

3/9/2019

I managed to fix it by adding:

env:
  - name: ELASTICSEARCH_URL
    value: "http://elasticsearch-service:9200"
  - name: ELASTICSEARCH_PORT
    value: "9200"
  - name: SERVER_BASEPATH
    value: /api/v1/namespaces/default/services/kibana-service:5601/proxy
  - name: SERVER_HOST
    value: "0.0.0.0"

What really solved is the SERVER_BASEPATH env.

-- Yagel
Source: StackOverflow

3/9/2019

Don't use switch --elasticsearch.url use environment variable ELASTICSEARCH_URL instead.

apiVersion: v1
kind: Pod
metadata:
  name: kibana
  labels:
    app: kibana
spec:
  ports:
  containers:
  - name: kibana
    image: kibana:6.6.1
    command: ["/bin/sh"]
    args: ["-c", "bin/kibana"]
    env:
    - name: ELASTICSEARCH_URL
      value: "http://elasticsearch-service:9200"

I suggest you also, read my answer in another thread for more detailed k8s DNS explanation.

-- ozlevka
Source: StackOverflow