How To Deploy Heartbeat On Kubernetes With ECK and SSL
In my previous stories I covered how we can Deploy Kibana and Elasticsearch using Elastic Cloud On Kubernetes (ECK) and how we can Deploy Logstash and Filebeat using Elastic Cloud On Kubernetes.
In today’s story I’m going to cover how we can deploy Heartbeat, one of the key tools of the Elastic Stack and the one that makes sure all your hosts are still up by asking them a simple question: Are you alive? Heartbeat then ships this information to Elasticsearch with other information for further analysis.
If you still haven’t got Elasticsearch, Kibana and Logstash deployed, make sure you read the stories linked above.
We will be going through:
• Configure Kubernetes Clusterrolebinding
• Configure Kubernetes Config Map (With heartbeat.yml)
• Configure Kubernetes Deployment
• Deploy Heartbeat On Kubernetes
• Add Heartbeat Index Template to Elasticsearch
• Alternative: Connect Heartbeat directly with Elasticsearch
CONFIGURE KUBERNETES CLUSTERROLEBINDING
To allow Heartbeat to see the all nodes, services and pods in our cluster, we must define a Service Account, a Cluster Role and then bind them. You can do it by running kubectl apply -f heartbeat-authorization.yml
in the same directory where the file below is located.
CONFIGURE HEARTBEAT CONFIG MAP (With heartbeat.yml)
Before we can actually deploy our Heartbeat instance, we must set up its properties and the hosts we want to track. To do it we will create a configmap with the following file heartbeat.yml
.
The heartbeat.yml
file will define all the hosts you want to track, how you want to do it and any other heartbeat configuration.
In the example below you can see:
- We have defined a file named heartbeat.yml
- We have defined three different types of monitors,
icmp,
tcp,
andhttp
- We have enabled auto discovery for all nodes of our cluster
- We have the output as the Logstash instance we had previously deployed in our cluster.
Now that you have your monitors set up, you can deploy the config map by running: kubectl apply -f heartbeat-cm.yml
DEPLOY HEARTBEAT ON KUBERNETES
Now that we have everything set, we can deploy Heartbeat by running kubectl apply -f heartbeat-deployment.yml
in the same directory where the file below is located.
Remember that the Elastic Operator deploys some default objects for us such as the service named elastic-es-http
and the secret elasticsearch-es-elastic-user
which come in handy in the configuration of this file.
You can check Heartbeat’s data is being shipped by accessing Kibana and going to: Stack Management > Index Management. You should see your new heartbeat index in there as logstash-heartbeat
if you followed our story on Deploying Logstash and Filebeat On Kubernetes With ECK and SSL.
ADD HEARTBEAT INDEX TEMPLATE TO ELASTICSEARCH
If you open the Uptime dashboard on Kibana you will probably see an Internal Server Error, that’s because we still need to add Heartbeat’s template to Elasticsearch. You can do it by:
Get Heartbeat Pod’s Name:
kubectl get pods
Access The Pod
kubectl exec -it heartbeat-69gunq779f5-l7rtr -- bash
Run The Command To Generate The Template
./heartbeat export template > heartbeat.template.json
Exit The Pod
exit
Copy The File To Your Local Machine
kubectl cp <POD-NAME>:heartbeat.template.json /Users/RaphaelDeLio/heartbeat.template.json
Send A Put Request To Your Elasticsearch Instance
curl -XPUT -H 'Content-Type: application/json' https://<YOUR ELASTIC SEARCH IP ADDRESS>:9200/_template/heartbeat-7.9.3 -d@heartbeat.template.json
Configure The Template In Kibana
In Kibana, access: Stack Management > Index Management > Index Templates > heartbeat-7.9.3 > Manage > Edit
And add the Index Pattern: *heartbeat*
Save it and now you should be able to see all your monitors on the Uptime section of Kibana!
Contribute
Writing takes time and effort. I love writing and sharing knowledge, but I also have bills to pay. If you like my work, please, consider donating through Buy Me a Coffee: https://www.buymeacoffee.com/RaphaelDeLio
Or by sending me BitCoin: 1HjG7pmghg3Z8RATH4aiUWr156BGafJ6Zw
Follow Me on Social Media
Stay connected and dive deeper into the world of Elasticsearch with me! Follow my journey across all major social platforms for exclusive content, tips, and discussions.