Elastic Kubernetes Service (EKS) Ingress routing with Nginx for Grafana and Prometheus.

Search for a command to run...

No comments yet. Be the first to comment.
Maintaining the inventory file while working with Ansible with AWS can be a difficult process owing to frequent changes in dynamic components of the infrastructure. Fortunately, there is a convenient solution called Ansible Dynamic Inventory. Dynamic...

The finished product of this project is terraform code that builds an AWS environment with three EC2 instances. The Jenkins CI/CD Pipeline will be triggered when the code is pushed to a GitHub repository via GitHub Webhook. What is Jenkins? Jenkins i...

In this article, you will learn how to create a Jenkins AMI using Hashicorp Packer and Ansible Playbook. What is Packer? Packer is an open-source tool for creating identical machine images for multiple platforms from a single source configuration. Pa...

Protecting your AWS account access keys is critical for protecting your company's cloud infrastructure. Managing several accounts, on the other hand, can be complicated and time-consuming. aws-vault secures the storage and management of access keys f...

In this article, you will learn how to use Ingress-NGINX Controller for Kubernetes to route traffic to Grafana and Prometheus respectively.
In Kubernetes, an Ingress is an API object that manages external access to services within a cluster. It provides a way to route incoming traffic to different services based on the requested host or path. Essentially, an Ingress acts as a traffic controller for incoming requests.
An Ingress resource defines a set of rules that determine how inbound connections should be routed to the appropriate backend services. It allows you to configure rules for HTTP and HTTPS traffic, including specifying hostnames, paths, and backend services.
A Load Balancer is responsible for distributing traffic at the network or transport layer, while Ingress provides routing and load balancing capabilities at the application layer. Load Balancer is typically provided as an external service by cloud providers, while Ingress is an API object in Kubernetes that requires an Ingress controller to function. Both are important for managing external access to services in a Kubernetes cluster, but they serve different purposes and operate at different layers of the network stack.
AWS Account.
An EKS(Elastic Kubernetes Service) cluster.
A Kubectl installation with your Kubernetes cluster from the step above is configured as the primary cluster.
The Helm CLI.
Install Nginx Ingress in your cluster using Helm, add the ingress-nginx repository to Helm, then run helm repo update . After we have added the repository we can deploy using the chart ingress-nginx/ingress-nginx .
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
Override helm chart default values, and create a file called nginx-values.yaml in a directory called nginx with the following.
controller:
setAsDefaultIngress: true
service:
annotations:
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: 'true'
service.beta.kubernetes.io/aws-load-balancer-type: nlb
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp This annotation specifies the backend protocol for the NLB. In this case, it is set to TCP, indicating that the traffic between the NLB and the pods behind it should use the TCP protocol.
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: 'true' This annotation enables cross-zone load balancing for the NLB. When set to true, the NLB can distribute traffic evenly across all available zones in the specified target group, even if the pods or instances are located in different availability zones.
service.beta.kubernetes.io/aws-load-balancer-type: nlb This annotation sets the type of load balancer to be created as an NLB. An NLB is a Layer 4 (TCP/UDP) load balancer provided by AWS that operates at the network level and can handle large-scale traffic.
The following command installs the nginx chart with the release name ingress-nginx:
helm install ingress-nginx ingress-nginx/ingress-nginx -f nginx/nginx-values.yaml
kubectl get pods
Output:

kubectl get services
Output:

kube-Prometheus-stack collects Kubernetes manifests, Grafana dashboards, and Prometheus rules combined with documentation and scripts to provide easy-to-operate end-to-end Kubernetes cluster monitoring with Prometheus using the Prometheus Operator.
Install kube-prometheus-stack in your cluster using Helm, add the prometheus-community repository to Helm, then run helm repo update . After we have added the repository we can deploy using the chart prometheus-community/kube-prometheus-stack .
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
The following command installs the kube-prometheus-stack chart with the release name kube:
helm install kube prometheus-community/kube-prometheus-stack
kubectl get pods -l release=kube
Output:

kubectl get services -l release=kube
Output:

Now that the ingress controller and kube-prometheus-stack are running in the cluster, we can expose the services using ingress.
The annotation kubernetes.io/ingress.class: nginx is used to specify the Ingress controller class to be used for a Kubernetes Ingress resource.
Create an ingress named ingress.yaml with the following:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
name: kube-stack-ingress
labels:
name: kube-stack-ingress
spec:
rules:
- host: grafana.tafaribeckford.com #Use your own domain
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: kube-grafana
port:
number: 80
- host: prom.tafaribeckford.com #Use your own domain
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: kube-kube-prometheus-stack-prometheus
port:
number: 9090
Create the resource
kubectl apply -f ingress.yaml
Perfect! Let’s check that it’s working
Grafana Dashboard:

Prometheus Dashboard:

A Kubernetes Ingress provides a reliable method for making your services accessible from outside the cluster. It simplifies the management of routing rules by consolidating them into a single resource and offers flexible configuration options for these rules.