DEV Community

Cover image for Monitor and Visualize Nginx Ingress Controller Metrics on Amazon EKS with Prometheus & Grafana
Rajit Paul for AWS Community Builders

Posted on

13

Monitor and Visualize Nginx Ingress Controller Metrics on Amazon EKS with Prometheus & Grafana

In today’s digital landscape, it is very necessary to figure out trends in our data and act accordingly to ensure high availability of our application. Monitoring helps us to stay on top of the game and get insights on our product environment. An Ingress Controller acts as a bridge between Kubernetes Service and the external world and can be considered as a specialized load balancer for Kubernetes.

Pre-Requisites

  1. A Kubernetes Cluster (Create an EKS Cluster from scratch)
  2. Helm V3 (Helm Install Docs)

Install Kube-Prometheus-Stack using Helm

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts 
helm repo update 
helm install --create-namespace --namespace monitoring \
my-k8s-prom-stack prometheus-community/kube-prometheus-stack
Enter fullscreen mode Exit fullscreen mode

Once you have the stack installed you should have Prometheus, Grafana and AlertManager installed onto your cluster.

Kube Prometheus Stack

Install Nginx Ingress Controller

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx 
helm repo update 
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace \
--set controller.metrics.enabled=true \
--set controller.metrics.serviceMonitor.enabled=true \
--set controller.metrics.serviceMonitor.additionalLabels.release="my-k8s-prom-stack" \
--version=4.5.2 
Enter fullscreen mode Exit fullscreen mode

Along with installing the ingress controller we are setting the controller metrics as true which will populate an additional metrics service and creating a service monitor for that service which will feed data onto Prometheus, the additional Label would be as per the selector you have set on the Prometheus Operator, follow the later part for more details on this.

You can check the Service Monitor selector on your Prometheus Operator using:

kubectl get prometheus --namespace monitoring prometheus-svc-name –oyaml (lookout for the section below on the manifest)

Service Monitor Selector on Prom Operator

Once Nginx controller is installed you can verify the services that are spawned using:

kubectl get svc --namespace ingress-nginx

Ingress Controller Services

Service Monitor

Monitor and Visualize Nginx Controller Metrics

To access the Prometheus and Grafana you can set ingress objects
Sample Ingress Manifest:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:    
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: 5m  
  name: prometheus-ingress
  namespace: monitoring
spec:
  rules:
  - host: prom.mydomain.com
    http:
      paths:
      - backend:
          service:
            name: my-k8s-prom-stack-kube-pro-prometheus
            port:
              number: 9090
        path: /
        pathType: ImplementationSpecific
Enter fullscreen mode Exit fullscreen mode

Generate some load on the Ingress Controller by hitting the Ingress Endpoints.

Access Prometheus and Grafana to query and visualize the controller metrics:
Prometheus Console
Prom Query to check the number of 200 requests on ingress:
nginx_ingress_controller_requests{status=~'2..'}

Prom Console

Import Nginx Controller Dashboard on Grafana and visualize the metrics (Dashboard ID: 9614)

Grafana Dashboard

Thank you for reading this, you can follow me for more such content, or reach out to me on Linkedin.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay