k8s monitoring

a k8s cluster needs monitoring when it is being used by multiple teams in a organization, as there might be many issues in the cluster and if we have a good monitoring system in place, we can easily identify the issues and resolve them! 2 such tools are Prometheus and Grafana

Prometheus

  • Prometheus is a monitoring tool that fetches all the information about a k8s cluster and monitors the cluster events such as pod, deployment or any other resource failures and can also be used to set up triggers such as alerts and alarms!
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
 
helm repo update
 
helm install prometheus prometheus-community/prometheus
 
kubectl get pods | grep prometheus
  • when installed, prometheus creates many pods and services in the cluster that can be used to monitor the cluster for ex we can expose the prometheus server:
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-ext

Grafana

  • Grafana is a visualization tool that helps visualize the metrics of the k8s cluster in forms of graphs and charts!
helm repo add grafana-community https://grafana-community.github.io/helm-charts
 
helm repo update
 
helm install grafana grafana-community/grafana
  • when installed, grafana creates a service in the cluster that can be then exposed to directly access it from the browser
kubectl expose svc grafana --type=NodePort --target-port=3000 --name=grafana-server-ext
 
service/grafana-server-ext exposed
 k get secrets -n default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
  • use it to decode the password for the grafana application

202603292054