Mar 4, 2019
To test a small application I needed an Elasticsearch and Kibana to visualize the data, as this application is running on a minikube I’ve decided to create this Elasticsearch + Kibana stack on minikube. This is a pretty simple setup and suitable for a development environment only.
To create the Elasticsearch I used a stateful set to persist the data on my local machine under the dir /mnt/data (see volumes definition):
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: elasticsearch
spec:
serviceName: "elasticsearch"
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
env:
- name: discovery.type
value: single-node
ports:
- containerPort: 9200
name: client
- containerPort: 9300
name: nodes
volumeMounts:
- name: data
mountPath: /usr/share/elasticsearch/data
volumes:
- name: data
hostPath:
path: /mnt/data
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
service: elasticsearch
spec:
ports:
- port: 9200
name: client
- port: 9300
name: nodes
selector:
app: elasticsearch
Then, create the StatefulSet and Service:
kubectl create -f es-stafulset.yml
Note that this will create only one replica and I defined the environmental variable “discovery.type” to “single-node” to run with only one replica. This will expose the service using the name elasticsearch, I decided to do that because usually this is the name used by Kibana and other application to automatically discover the elasticsearch cluster.
Now, the kibana configuration:
apiVersion: apps/v1
kind: Deployment
metadata:
name: kibana-deployment
labels:
app: kibana
spec:
replicas: 1
selector:
matchLabels:
app: kibana
template:
metadata:
labels:
app: kibana
spec:
containers:
- name: kibana
image: docker.elastic.co/kibana/kibana:6.6.1
ports:
- containerPort: 5601
name: webinterface
---
apiVersion: v1
kind: Service
metadata:
name: kibana
labels:
service: kibana
spec:
type: NodePort
ports:
- port: 5601
name: webinterface
selector:
app: kibana
The Kibana configuration is simpler than elasticsearch as I’m using just to visualize the data, I had no need to persist the kibana data, so the only detail is that the service is being exposed using NodePort. To create the deployment and service we can run:
kubectl create -f kibana-deployment.yml
After deploying the kibana deployment we can get the node port running:
kubectl get services -o wide
With the nodeport we should be able to access kibana on the browser.