I configured a web application with prometheus to monitor its:
version
http_requests_total
http_request_duration_seconds
http_request_duration_seconds_count
http_request_duration_seconds_sum
- AWS
- Kubernete
- Docker
- Prometheus & Grafana (Monitoring)
-
First of all, A web application was prepared to host all of the metrics data at endpoint
/metrics
with the help of prometheus library so that the configured prometheus can scrape metrics data from the web application endpointmetrics
at an interval. -
Then, A Container image was built of the application, That can be found here.
-
Then I deployed a deployment resource in my running Kubernetes cluster on AWS EKS:
apiVersion: apps/v1 kind: Deployment metadata: labels: app.kubernetes.io/name: prometheus-example-app name: prometheus-example-app spec: replicas: 1 selector: matchLabels: app.kubernetes.io/name: prometheus-example-app template: metadata: labels: app.kubernetes.io/name: prometheus-example-app spec: containers: - name: prometheus-example-app image: mdsahiloss/prometheus-example-app:latest ports: - name: web containerPort: 8080
-
And then, I Created a
ClusterIP
service inside K8s, So that other resources in K8s can communicate with the application pods. -
And then, I installed a promentheus operator in my running Kubernetes cluster on AWS EKS, By following the instructions available here.
-
And then created a resource
ServiceMonitor
(CRD of this resource is provided by the installed Prometheus-Operator) inside K8s cluster indefault
namespace:apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: labels: app.kubernetes.io/name: prometheus-example-app-svc-monitor name: prometheus-example-app-svc-monitor spec: selector: matchLabels: app.kubernetes.io/name: prometheus-example-app-svc endpoints: - port: http namespaceSelector: any: true
That's it after this, I was able to see all the metrics generated by my application on the prometheus web which is runnning in my K8s Cluster.