Project 2: Deploying a .NET & Python Three-tier Application on KIND with Prometheus and Grafana monitoring

Project 2: Deploying a .NET & Python Three-tier Application on KIND with Prometheus and Grafana monitoring

ยท

4 min read

This project sets up a three-tier architecture using:

  • Frontend: .NET Web Application.

  • Backend: Python REST API.

  • Database: MySQL.

We will deploy this on a KIND cluster with monitoring using Prometheus and Grafana.


1. Prerequisites

Install KIND, kubectl, and Docker

Refer to the previously described installation process.

Install Helm

  1. Download and install Helm version 3 or later:

     curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
     chmod +x get_helm.sh
     ./get_helm.sh
    

  2. Verify the installation:

     helm version
    

Create a KIND Cluster

  1. Create a kind-cluster-config.yaml file with the following content:

     kind: Cluster
     apiVersion: kind.x-k8s.io/v1alpha4
    
     nodes:
     - role: control-plane
       image: kindest/node:v1.31.2
     - role: worker
       image: kindest/node:v1.31.2
     - role: worker
       image: kindest/node:v1.31.2
    
  2. Create the cluster:

     kind create cluster --config kind-cluster-config.yml --name my-kind-cluster
    


2. Install Prometheus and Grafana Using Helm

  1. Add the Helm repositories:

     helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
     helm repo add grafana https://grafana.github.io/helm-charts
     helm repo update
    
  2. Deploy Prometheus and Grafana:

    • Install Prometheus:

        helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace
      
    • Install Grafana:

        helm install grafana grafana/grafana --namespace monitoring --create-namespace
      

  3. Alternatively, install the entire stack (Grafana, Prometheus, AlertManager, etc.) in one command:

     helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
       --namespace monitoring --create-namespace
    

    This command:

    • Installs the Kube Prometheus Stack.

    • Creates the monitoring namespace if it doesn't exist.


3. Verify Prometheus and Grafana

  1. Check the pods:

     kubectl get pods -n monitoring
    
  2. Check the services:

     kubectl get svc -n monitoring
    

Edit Service Type to NodePort

  1. Modify the service type for Prometheus and Grafana:

     kubectl edit svc grafana -n monitoring
     kubectl edit svc prometheus-server -n monitoring
    
  2. In the YAML file, locate the type under spec and change it to NodePort:

     spec:
       type: NodePort
    

4. Access Prometheus and Grafana Using Port Forwarding

  1. Forward ports for Prometheus and Grafana:

     kubectl port-forward -n monitoring svc/prometheus-server 9090:80 --address=0.0.0.0 &
     kubectl port-forward -n monitoring svc/grafana 3000:80 --address=0.0.0.0 &
    

  1. Access Prometheus dashboard with all metrics.

Retrieve Admin Password for Grafana

Retrieve the Grafana admin password:

kubectl get secret -n monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

Add Prometheus as a Data Source in Grafana

  1. Add a new connection to Grafana:

    • Set Prometheus server URL.

    • Save the data source.

  2. Create a dashboard:

    • Go to Dashboard > Add Visualization.

    • Select Prometheus as a data source.

    • Choose query and namespace.

  3. Import a pre-built dashboard:

    • Visit the Grafana dashboard website.

    • Copy the Dashboard ID (e.g.).

    • Import the dashboard in Grafana:

      • Paste the Dashboard ID.

      • Select Prometheus as the data source.

      • Click on Import.

we can see Dashboard with all the metrics available

5. Deploy the Application

Clone the Repository

git clone https://github.com/imkiran13/fullstack-voting-app.git

Verify Pods and Services

  1. Check the pods:

     kubectl get pods
    
  2. Check the services:

     kubectl get svc
    

Port Forward Services

  1. Forward ports for the Vote and Result services:

     kubectl port-forward svc/vote 5000:5000 --address=0.0.0.0 &
     kubectl port-forward svc/result 5001:5001 --address=0.0.0.0 &
    


6. Update Security Group Rules

Edit your security group inbound rules to allow traffic on port 5000.


7. Access the Application

Access the application on port 5000 and monitor the load using the dashboard.

Now check dashboard for change in data

Summary

This document provides a step-by-step guide to setting up a three-tier application architecture with monitoring using Prometheus and Grafana on a KIND cluster. It includes setting up Helm, deploying Prometheus and Grafana, and configuring access and monitoring for the application.

ย