Skip to content

Metricbeat monitoring for Kubernetes

Rui Wang edited this page Jun 21, 2024 · 2 revisions

To monitor Microk8s Kubernetes cluster on NREC, we can run Metricbeat on Kubernetes to collect and send the metrics data to the Elasticsearch cluster for observation.

We deploy Metricbeat as a DaemonSet to ensure that there’s a running instance on each node of the cluster.

Deploy Metricbeat on Microk8s Kubernetes cluster with Ansible

We have implemented Ansible tasks in microk8s role in microk8s-NREC-deployment repo to deploy Metricbeat

Set up Manually

  1. Download the official manifest file

On one of the Microk8s nodes, we run the following command to download manifests for the deployment of Metricbeat on Kubernetes. Note: the version number should be at least the same as the version of the Elasticsearch cluster, ie. 8.12.

curl -L -O https://raw.githubusercontent.com/elastic/beats/8.12/deploy/kubernetes/metricbeat-kubernetes.yaml
  1. Configuration

a. Connection to Elasticsearch cluster

To let Metricbeat send events to our Elasticsearch cluster, https://observe.ub.uib.no, for observation, in the download manifest file, we need to edit the following parameters:

Note: we need to give the corresponding password of elastic username for the Elasticsearch cluster. PS, we could also create a Kubernetes secret for this password, not for now, we could just use an environment variable for it.

- name: ELASTICSEARCH_HOST
  value: "https://observe.ub.uib.no"
- name: ELASTICSEARCH_PORT
  value: "443"
- name: ELASTICSEARCH_USERNAME
  value: elastic
- name: ELASTICSEARCH_PASSWORD
  value: changeme

b. Setting for proper tolerations

We run Metricbeat on Microk8s control plane nodes, so we may need to update the Daemonset spec to include proper tolerations:

spec:
...
...
...
  tolerations:
  - key: node-role.kubernetes.io/control-plane
    effect: NoSchedule
  containers:
  - name: metricbeat
...
...
...

c. Deploy

To deploy Metricbeat to Kubernetes, run:

kubectl apply -f metricbeat-kubernetes.yaml

To check the status, run:

kubectl -n kube-system get ds/metricbeat