Simplified Kubernetes Monitoring with Minikube, Helm, Prometheus, and Grafana

Simplified Kubernetes Monitoring with Minikube, Helm, Prometheus, and Grafana




Introduction:

This article guides you through setting up a local Kubernetes cluster using Minikube and deploying essential monitoring tools like Prometheus and Grafana using Helm. By the end, you'll have a functional setup that allows you to monitor your Kubernetes cluster's performance and health metrics.


Step 1: Setup Minikube

Minikube allows you to run Kubernetes locally. Follow these steps to install and start Minikube on your EC2 instance:

  1. Update and Install Dependencies:

sudo su

# Update apt package index and install Docker
sudo apt update && apt -y install docker.io

# Install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x ./kubectl && sudo mv ./kubectl /usr/local/bin/kubectl

# Install Minikube
curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v1.24.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

# Install conntrack (dependency for Minikube)
apt install conntrack

# Install crictl (optional, for container runtime inspection)
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.22.0/crictl-v1.22.0-linux-amd64.tar.gz
tar -zxvf crictl-v1.22.0-linux-amd64.tar.gz
sudo mv crictl /usr/local/bin/
crictl --version        

2. Start Minikube:

Start Minikube with the --vm-driver=none flag to run it directly on your EC2 instance:

minikube start --vm-driver=none
minikube status        


Step 2: Install Helm

Helm is a package manager for Kubernetes that simplifies the deployment and management of applications on Kubernetes.

# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash        


Step 3: Add Helm Repositories

Helm repositories are where Helm charts (packages of pre-configured Kubernetes resources) are stored.

# Add Prometheus Helm repository
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

# Add Grafana Helm repository
helm repo add grafana https://grafana.github.io/helm-charts

# Update Helm repositories
helm repo update        


Step 4: Install Prometheus

Prometheus is a monitoring and alerting toolkit for containerized environments. Use Helm to install Prometheus on your Kubernetes cluster.

# Install Prometheus using Helm
helm install prometheus prometheus-community/prometheus        


Step 5: Install Grafana

Grafana is a multi-platform open-source analytics and interactive visualization web application.

# Install Grafana using Helm
helm install grafana grafana/grafana        


Step 6: Access Grafana and Prometheus

To access Grafana and Prometheus, you need to expose their services. Here, we use NodePort for simplicity.


  • Expose Prometheus

kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-np        

  • Expose Grafana

kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-np        

  • Expose Prometheus Kube State Metrics

kubectl expose service prometheus-kube-state-metrics --type=NodePort --target-port=8080 --name=prometheus-kube-state-metrics-np        


Step 7: Get NodePort

kubectl get svc        

This command will display the services and their NodePort numbers, which you will use to access Grafana and Prometheus.


Step 8: Edit inbound rules

Allow ports for Prometheus (30847), Grafana (31504), and Kube State Metrics (30842) services.


Step 9: Access the Services

After getting the NodePort numbers from Step 7 and Step 8 you can access Grafana and Prometheus using the following URLs:

  • Prometheus: https://<EC2-Public-IP>:<Prometheus-NodePort>
  • Grafana: https://<EC2-Public-IP>:<Grafana-NodePort>

Replace <EC2-Public-IP> with the public IP address of your EC2 instance, and <Prometheus-NodePort> and <Grafana-NodePort> with the actual NodePort numbers.


  • Prometheus:

https://13.201.125.51:30847

  • Grafana:

https://13.201.125.51:31504


Step 10: Login to Grafana

To log in to Grafana after installation, retrieve the admin password:

kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo        
Login with:

  • Username: admin
  • Password: (The password retrieved from the command above)



After logging in, it's recommended to change the admin password for security:

  1. Click on the user icon (bottom left corner).
  2. Select "Preferences".
  3. Click on "Change Password".
  4. Enter and save the new password.


Step 11: Set Up Prometheus Data Source


  • Click on Connections > Data Sources > Add Data Source.

  • Choose Prometheus.


  • In the URL field, enter the URL of your Prometheus service:

https://<EC2-Public-IP>:<Prometheus-NodePort>

e.g: https://13.201.125.51:30847        

  • Save & Test the data source.


Step 12: Create a Dashboard

  1. Import Kubernetes Cluster Autoscaler Dashboard:

  • Go to Dashboards > Create Dashboard > Import a dashboard.



  • Click Load and configure the dashboard.



  • Select the data source that you have created:


  • Click import:


Step 13: Adjust Dashboard as Needed:

  • Customize the dashboard settings, panels, and variables according to your requirements.


Step 14: Save and View Dashboard

  1. Save Dashboard:

  • Click Save > Save As and give your dashboard a name.


2. View Dashboard:

  • Access your newly created dashboard from the Grafana dashboard list.


By following these steps, you've set up a local Kubernetes cluster using Minikube, installed monitoring tools Prometheus and Grafana using Helm, and created a dashboard in Grafana that uses Prometheus as a data source. This setup allows you to effectively monitor your Kubernetes applications and infrastructure.

Feel free to customize the dashboard further based on your specific monitoring needs. This configuration provides a solid foundation for monitoring Kubernetes clusters locally using Minikube.


Ali Bashir

Senior DevOps Architect | Multi-Cloud Solutions Expert (AWS, Azure, GCP) | Infrastructure Automation & CI/CD Specialist | Kubernetes & Microservices | DevSecOps Practitioner

5 个月
Uzair Ahmad

DevOps Engineer | Infrastructure as Code Enthusiast | Container Orchestration Specialist | CI/CD Pipeline Guru | AWS | Azure

5 个月

Informative ??

要查看或添加评论,请登录

社区洞察

其他会员也浏览了