This project demonstrates the setup and basic functionality of Prometheus for monitoring a Kubernetes cluster and services. The implementation includes a Prometheus server, Node.js applications for simulating requests, and a configuration setup for Kubernetes.
Before getting started, ensure you have the following installed:
- Clone the repository:
git clone https://github.com/Arcaici/kubernetes_prometheus_configuration cd kubernetes_prometheus_configuration
- Apply the prometheus configuration & release:
kubectl apply -f prometheus_full_setup.yml
- Apply the Kube-state-metrics configuration:
kubectl apply -f ./kubestatemetricservice/kubestatemetrics_full_setup.yml
- Apply the simulation server:
docker build -t simulation-server ./serviceToScrape/ kubectl apply -f ./serviceToScrape/simulation_deployment.yml
- Apply JSON pseudo storage service:
docker build -t json-data-server ./pseudoStorageService/ kubectl apply -f ./pseudoStorageService/jsonstorage_deployment.yml
- prometheus_full_setup.yml: Kubernetes file for ClusterRole, Service and Deployment configuration for Prometheus.
- kubestatemetrics_full_setup.yml: Kubernetes file for ClusterRole, Service and Deployment configuration Kube-State-Metrics service.
- simulation_deployment.yml: Kubernetes deployment running a NodeJS server with prometheus custom metrics.
- jsonstorage_deployment.yml: Kubernetes deployment running a NodeJS server with query to Prometheus promQL endpoint that save query results in JSON format.
- Using the simulation_script.py for test the custom metrics you need first to use kubernetes port-farwarding:
and then run the python script.
kubectl port-forward -n simulation deployment.apps/simulation 8081:3000
- If you want to access prometheus console and GUI you need to port-forward to:
and then access from your web browser to http://localhost:9090 .
kubectl port-forward deployment.apps/prometheus 8080:9090 -n monitoring
- If you want to check the last prometheus metrics saved from pseudo storage service you need to forward:
and then access from your web browser to http://localhost:3001/lastdata .
kubectl port-forward -n monitoring service/json-data-server-service 3001:3001
Using a Node.js server to store long-term time series data is not the recommended approach; typically, tools like Thanos or Grafana are employed for such purposes. In this case, I chose not to implement additional services to avoid complicating the situation and exceeding the scope of the guide. Exploring how Thanos, coupled with Prometheus, can enhance the monitoring system could be an interesting avenue for further study.