Kafka monitoring of K8S (Prometheus + Grafana)

For Kafka deployed on K8S, Prometheus + Grafana is a commonly used monitoring solution. Today, we will come to actual combat to monitor Kafka in K8S environment through Prometheus + Grafana;

Ready to work

Today ’s focus is on Kafka monitoring, so K8S, Helm, Kafka, Prometheus, Grafana and other services are all ready. The following provides some links, which can be used as a reference when you make related deployments:

  1. Build K8S: "kubespray2.11 install kubernetes1.15"
  2. Build Helm: "Deploy and Experience Helm (Version 2.16.1)"
  3. Build Prometheus and Grafana: "kubernetes1.15 rapid deployment of prometheus and grafana"
  4. Deploying Kafka: "Rapid deployment of Kafka in K8S environment (accessible outside K8S)"

Version Information

  1. Governors : 1.15
  2. Kubernetes host: CentOS Linux release 7.7.1908
  3. NFS service: IP address 192.168.50.135, folder / volume1 / nfs-storageclass-test
  4. Helm:2.16.1
  5. Kafka:2.0.1
  6. Zookeeper:3.5.5
  7. Prometheus:2.0.0
  8. Grafana : 5.0.0

After preparation, you can start actual combat;

Confirm kafka-exporter parameters

The kafka-exporter to be deployed needs to obtain data from kafka, so kafka-exporter parameters must be prepared

  1. Check the Kafka service where the TYPE is ClusterIP, as shown in the red box below:
    Insert picture description here
  2. The service name in the above red box is kafka and the port is 9092 , so the kafka information configured later in kafka-exporter is kafka: 9092

Actual operation

  1. Add the Helm warehouse (the warehouse has the kafka-exporter we need): helm repo add gkarthiks https://gkarthiks.github.io/helm-charts
  2. 下载kafka-exporter:helm fetch gkarthiks/prometheus-kafka-exporter
  3. Unzip the downloaded chart file: tar -zxvf prometheus-kafka-exporter-0.1.0.tgz
  4. Enter the unzipped directory: cd prometheus-kafka-exporter
  5. Modify the values.yaml file, as shown in the red box below, kafka: 9092 is the address to access kafka under the same namespace:
    Insert picture description here
  6. Execute in the directory where the values.yaml file is located: helm install --name-template kafka-exporter -f values.yaml. --Namespace kafka-test (kafka's namespace is kafka-test, and the namespace here must be consistent with kafka)
  7. Check whether the service and pod are ready:
    Insert picture description here
  8. At this point, we have deployed kafka-exporter and can provide prometheus with monitoring data, but prometheus does not know to come here to collect data, so next we need to configure prometheus;
  9. Confirm the access address of the kafka-exporter service. Prometheus collects the data to be used. The name and port are shown in the red box in the figure below, so you can stitch the access address across the namespace: kafka-exporter-prometheus-kafka-exporter.kafka-test. svc.cluster.local: 9308
    Insert picture description here
  10. If you are referring to the prometheus deployed by "kubernetes1.15 rapid deployment of prometheus and grafana" , please open the configmap.yaml file downloaded during deployment , which contains the configuration of prometheus, if it is deployed by other means, please find prometheus according to your deployment .yml location;
  11. configmap.yaml adds the content in the red box below, so that prometheus can collect kafka-exporter data:
    Insert picture description here
  12. Make the configuration effective: kubectl apply -f configmap.yaml
  13. At this time, the prometheus container still uses the old configuration. In order for the configuration to take effect, the pod of prometheus must be deleted, so that the new pod automatically created by K8S uses the new configuration to find the pod of prometheus: kubectl get pods -n kube -system
    Insert picture description here
  14. Delete the old pod: kubectl delete pod prometheus-68545d4fd8-f5q2w -n kube-system
  15. Wait for a new pod to be created automatically;
  16. Next, log in to Grafana, configure the monitoring page, as shown below, do template import operation:
    Insert picture description here
  17. Enter the number 7589 on the page of import template:
    Insert picture description here
  18. When choosing a data source, you must choose prometheus, as shown below:
    Insert picture description here
  19. At this time, if your kafka has
    Insert picture description here
    sent and received messages, you can immediately see the data: At this point, the kafka monitoring in the K8S environment has been deployed, I hope this article can give you some reference;

Welcome to pay attention to my public number: programmer Xinchen

Insert picture description here

Published 376 original articles · praised 986 · 1.28 million views

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/105466788