Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

In this example we are going to run Grafana in Kubernetes to visualise Elasticsearch logs. It is a very simple process and assumes your Elasticsearch is running in the same namespace monitoring as Grafana.


Configuration


apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: monitoring
labels:
app: grafana
spec:
type: ClusterIP
selector:
app: grafana
ports:
- name: http
protocol: TCP
port: 3000

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: grafana-data
namespace: monitoring
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana
namespace: monitoring
labels:
app: grafana
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
containers:
- image: grafana/grafana:8.1.1
name: grafana
ports:
- name: http
protocol: TCP
containerPort: 3000
volumeMounts:
- name: grafana-data
mountPath: /var/lib/grafana
volumes:
- name: grafana-data
persistentVolumeClaim:
claimName: grafana-data

Setup


$ kubectl apply -f kibana.yaml

Port Forward


$ kubectl --namespace=monitoring port-forward service/grafana 3000:3000

Access UI


Visit http://127.0.0.1:3000/ and login with (admin:admin) credentials. Use Elasticsearch for the data source setup and use values below.


- URL: http://elasticsearch:9200
- Index: kubernetes-logs

The elasticsearch is the name of the Kubernetes service.


Graph