The Pods Health Checker AI project combines a Bash shell script and a Python script to enhance Kubernetes pod monitoring by leveraging AI to diagnose and suggest solutions for pod issues. This tool provides a comprehensive way to scan pod statuses across namespaces or cluster-wide and generates actionable insights using Google Gemini.
- Pod Health Scanning: Scan Kubernetes pods cluster-wide or within specific namespaces.
- Status Reporting: Display the status of pods (Running, Pending, and Errors) in a visually appealing table format.
- Issue Diagnosis: Extract and analyze pod issues (e.g., CrashLoopBackOff) and get solutions using Google Gemini.
- Namespace Listing: Automatically list all namespaces within the cluster for easy selection.
- Response Storing: The AI response is stored in
CrashLoopBackOff.md
file based on issue extracted - Clusters Switch: List down all the clusters and easily switch between them
- Multiple Error Handing: if two or more than two errors are there then respective markdown file will be generated
- Python: Version 3.x
- Bash: Compatible with most Unix-based systems
- Google Gemini API Access: Ensure you have access and an API key for Google Gemini.
Create a requirements.txt
file with the following content:
google-generativeai
python-dotenv
Install the dependencies using pip:
pip install -r requirements.txt
Create a .env file in the root directory of your project and add your Google Gemini API key:
API_KEY=your_google_gemini_api_key
The Python script (get_gemini_solution.py) is used to get solutions for pod issues. It interacts with Google Gemini to generate solutions based on the issue description.
Example Command
python get_gemini_solution.py "CrashLoopBackOff"
🔔 Note: This Python Script is in the Shell Script so we dont need to run it as standalone
The Bash script (pods_health_checker.sh) is used to scan pods, check their status, and display the results in a table format. It also integrates with the Python script to fetch and display solutions for identified issues.
./pods_health_checker.sh
- Scan cluster-wide: Scans all namespaces in the Kubernetes cluster.
- Scan a specific namespace: Allows the user to select a namespace and scan pods within that namespace.
Available Kubernetes clusters:
kind-hack
minikube
k3d-dragon-1
🔄🗂️ Enter the name of the cluster you want to switch to: minikube
Switched to context "minikube".
Switched to cluster: minikube
Avaliable Namespaces:
default
dev
kube-node-lease
kube-public
kube-system
+---------------+---------------+---------------+
| Healthy Pods | Unhealthy Pods| Pending Pods |
+---------------+---------------+---------------+
| 5 | 2 | 1 |
+---------------+---------------+---------------+
+------------------------+-----------------------------+
| Pod Name | Description |
+------------------------+-----------------------------+
| crashing-pod-1234 | CrashLoopBackOff 🛠️ |
+------------------------+-----------------------------+
Fetching solution for: CrashLoopBackOff
Possible Solutions:- AI Response is saved as Markdown. Please check CrashLoopBackOff.md for the solution.
check the example CrashLoopBackOff.md to get a good understanding about the Pod Issue.
Feel free to fork the repository and submit pull requests. Contributions to improve functionality and add features are welcome.
This project is licensed under the MIT License.