ELK Stack (Elasticsearch, Logstash, Filebeat, Kibana) to Collect Logs from Applications On Kubernetes Cluster
In this video, we use the ELK Stack to collect logs of applications deployed on a Kubernetes cluster.
YouTube Link: https://youtu.be/A3W7ZZsBmn4?si=XOfX-FbMNVHKcxA6
- Docker Desktop (on Mac & Windows) or Docker Engine (on Linux)
- Kubectl
- Kubernetes (Minikube)
docker --versionkubectl version --clientminikube versionminikube start --cpus=4 --memory=8192 --driver=dockerkubectl get nodeskubectl create namespace demo-appskubectl apply -f app1.yamlkubectl apply -f app2.yamlkubectl create namespace loggingkubectl apply -f elasticsearch.yamlkubectl get pods -n loggingkubectl get pvc -n loggingkubectl get pv -n loggingkubectl apply -f kibana.yamlkubectl get pods -n loggingminikube service kibana -n logging --url- Listen for container logs from Filebeat
- Parse the logs
- Send the logs to Elasticsearch
kubectl apply -f logstash.yamlkubectl get all -n loggingListen for container logs from /var/log/containers/*.log
kubectl apply -f filebeat.yamlkubectl logs app1 -n demo-apps | tailkubectl logs app2 -n demo-apps | headkubectl run -i --rm --restart=Never curl --image=curlimages/curl -n logging -- curl http://elasticsearch:9200
kubectl run -i --rm --restart=Never curl --image=curlimages/curl -n logging -- curl http://elasticsearch:9200/_cat/indices?vkubectl exec -n logging -it <filebeat-pod> -- ls /var/log/containers/kubectl exec -n logging -it <logstash-pod> -- ls /usr/share/logstash/pipeline/
kubectl exec -n logging -it <logstash-pod> -- cat /usr/share/logstash/pipeline/logstash.conf- Explore on My Own
- Click Home Left Panel
- Go to Stack Management
- Click Index Patterns - "create an index pattern against hidden or system indices" name e.g: filebeat-*
- Select @timestamp in Timestamp field
- Click create index pattern.
- Go to Discover on the left panel of homepage to see logs from app1 and app2.
- On the left panel (under Available fields)
- Scroll down to the bottom to see e.g. log message, log.file.path, etc.
- Click to examine them.
kubectl apply -f nginx.yamlminikube service nginx-service -n demo-apps --url- Add filter
- Field = kubernetes.labels.app, Operator = is, Value = nginx & Save. (You may have to change timestamp next to the "Refresh button" to see some logs)
kubectl delete ns loggingkubectl delete ns demo-appsminikube stopminikube delete --all