Simplified Kubernetes Monitoring with Minikube, Helm, Prometheus, and Grafana
Muhammad Abdullah
DevOps Engineer | AWS Architect | Automation Expert | Container Maestro (Docker, Kubernetes) | Infrastructure as?Code?Maestro | Azure DevOps
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:
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.
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-np
kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-np
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:
Replace <EC2-Public-IP> with the public IP address of your EC2 instance, and <Prometheus-NodePort> and <Grafana-NodePort> with the actual NodePort numbers.
领英推荐
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
After logging in, it's recommended to change the admin password for security:
Step 11: Set Up Prometheus Data Source
https://<EC2-Public-IP>:<Prometheus-NodePort>
e.g: https://13.201.125.51:30847
Step 12: Create a Dashboard
Step 13: Adjust Dashboard as Needed:
Step 14: Save and View Dashboard
2. View Dashboard:
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.
Senior DevOps Architect | Multi-Cloud Solutions Expert (AWS, Azure, GCP) | Infrastructure Automation & CI/CD Specialist | Kubernetes & Microservices | DevSecOps Practitioner
5 个月Bilal Amjad
DevOps Engineer | Infrastructure as Code Enthusiast | Container Orchestration Specialist | CI/CD Pipeline Guru | AWS | Azure
5 个月Informative ??