Docker & Kubernetes
Bare metal

MicroK8s

Nginx Ingress

Prometheus

SRE | Prometheus Monitoring

Nginx Ingress Monitoring with Prometheus

Intro

After setting up your own Kubernetes cluster for production it is useful to introduce some kind of monitoring. Nowdays, it is natural to use Prometheus for Kubernetes monitoring.

Install

With MicroK8s it is very simple to install Nginx Ingress and Prometheus Monitoring stack.

	
	microk8s enable ingress observability
					

This will install Nginx Ingress controller needed to route traffic from the Internet to your PODs. It will also install Prometheus and Grafana inside your Kubernetes cluster. If you are using Lens, all stats and graphs shouls start to work after this.

Configure

After installation lots of stats will start to show automatically. If you want to monitor your Nginx Ingress then it is needed to make additional configuration.

First you need to create Ingress Service Monitor:

    
    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
        name: kube-prom-stack-nginx-ingress-microk8s
        namespace: observability
        annotations:
        meta.helm.sh/release-name: kube-prom-stack
        meta.helm.sh/release-namespace: observability
        labels:
        app.kubernetes.io/component: metrics
        app.kubernetes.io/instance: kube-prom-stack
        app.kubernetes.io/name: nginx-ingress-microk8s
        app.kubernetes.io/part-of: nginx-ingress-microk8s
        release: kube-prom-stack
    spec:
        selector:
        matchLabels:
            microk8s-application: nginx-ingress-microk8s
        endpoints:
        - honorLabels: true
            enableHttp2: true
            port: health
            path: /metrics
            interval: 5s
            scheme: http
        namespaceSelector:
        matchNames:
            - ingress
            - observability
            - kube-system
            - default
    

Then you need to add Service to allow Prometheus to reach your Ingress and collect metrics exposed on the port 10254. The path will be http://your_ingress:10254/metrics.


    apiVersion: v1
    kind: Service
    metadata:
    name: kube-prom-stack-nginx-ingress-microk8s
    namespace: ingress
    labels:
        microk8s-application: nginx-ingress-microk8s
        release: kube-prom-stack
    spec:
    ports:
        - port: 10254
        targetPort: 10254
        name: prometheus
        protocol: TCP
    selector:
        microk8s-application: nginx-ingress-microk8s