|
| 1 | +# 🚀 kdiff |
| 2 | + |
| 3 | +<div align="center"> |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +**A pretty command-line tool to monitor Kubernetes pod resource usage vs requests** |
| 10 | + |
| 11 | +Compare actual CPU and memory usage against requested resources with color-coded output for easy identification of over/under-utilized pods. |
| 12 | + |
| 13 | +</div> |
| 14 | + |
| 15 | +## ✨ Features |
| 16 | + |
| 17 | +- 🎨 **Color-coded output** - Instantly identify resource utilization patterns |
| 18 | +- 📊 **Detailed comparison** - See requested vs actual CPU and memory usage |
| 19 | +- 🌐 **Multi-namespace support** - Check single namespace or all at once |
| 20 | +- 🎯 **Flexible filtering** - Show only CPU, memory, or both |
| 21 | +- ⚡ **Performance focused** - Fast scanning with progress indicators |
| 22 | +- 🔧 **Customizable thresholds** - Adjust color coding to your needs |
| 23 | +- 📈 **Usage percentage** - Clear percentage differences for easy analysis |
| 24 | + |
| 25 | +## 🎨 Color Legend |
| 26 | + |
| 27 | +- <span style="color: cyan">**Cyan**</span> - Very under-utilized (< -90% by default) |
| 28 | +- <span style="color: green">**Green**</span> - Under-utilized (-90% to -20% by default) |
| 29 | +- <span style="color: yellow">**Yellow**</span> - Well-utilized (-20% to 0% by default) |
| 30 | +- <span style="color: red">**Red**</span> - Over-utilized (> 0% by default) |
| 31 | +- <span style="color: magenta">**Magenta**</span> - No resource requests set |
| 32 | + |
| 33 | +## 🚀 Installation |
| 34 | + |
| 35 | +### Option 1: Download Pre-built Binary |
| 36 | + |
| 37 | +```bash |
| 38 | +# Download the latest release for your platform |
| 39 | +curl -L https://github.com/Senk02/kdiff/releases/latest/download/kdiff-linux-amd64 -o kdiff |
| 40 | +chmod +x kdiff |
| 41 | +sudo mv kdiff /usr/local/bin/ |
| 42 | +``` |
| 43 | + |
| 44 | +### Option 2: Build from Source |
| 45 | + |
| 46 | +```bash |
| 47 | +# Clone the repository |
| 48 | +git clone https://github.com/Senk02/kdiff.git |
| 49 | +cd kdiff |
| 50 | + |
| 51 | +# Build the binary |
| 52 | +make build |
| 53 | + |
| 54 | +sudo chmod +x kdiff |
| 55 | + |
| 56 | +# Optional: Install to PATH |
| 57 | +sudo mv kdiff /usr/local/bin/ |
| 58 | +``` |
| 59 | + |
| 60 | +## 📋 Prerequisites |
| 61 | + |
| 62 | +- Kubernetes cluster with `metrics-server` installed and running |
| 63 | +- Valid `kubeconfig` file (usually at `~/.kube/config`) |
| 64 | +- Go 1.19+ (if building from source) |
| 65 | + |
| 66 | +## 🔧 Usage |
| 67 | + |
| 68 | +### Basic Usage |
| 69 | + |
| 70 | +```bash |
| 71 | +# Check current namespace |
| 72 | +kdiff |
| 73 | + |
| 74 | +# Check specific namespace |
| 75 | +kdiff -n kube-system |
| 76 | + |
| 77 | +# Check all namespaces |
| 78 | +kdiff -a |
| 79 | +``` |
| 80 | + |
| 81 | +### Advanced Options |
| 82 | + |
| 83 | +```bash |
| 84 | +# Show only CPU usage across all namespaces |
| 85 | +kdiff -a -o cpu |
| 86 | + |
| 87 | +# Show only memory usage in specific namespace |
| 88 | +kdiff -n production -o memory |
| 89 | + |
| 90 | +# Show only pods exceeding their requests |
| 91 | +kdiff -d |
| 92 | + |
| 93 | +# Ignore pods without resource requests set |
| 94 | +kdiff -i |
| 95 | + |
| 96 | +# Combine filters: only over-utilized pods with requests set |
| 97 | +kdiff -d -i |
| 98 | + |
| 99 | +# Use specific kubeconfig context |
| 100 | +kdiff --context my-cluster-context |
| 101 | +``` |
| 102 | + |
| 103 | +### Custom Color Thresholds |
| 104 | + |
| 105 | +```bash |
| 106 | +# Customize when colors appear (values are percentages) |
| 107 | +kdiff --color-red 10 --color-yellow -10 --color-cyan -75 |
| 108 | + |
| 109 | +# This means: |
| 110 | +# Red: > 10% over requests |
| 111 | +# Yellow: -10% to 10% of requests |
| 112 | +# Green: -75% to -10% under requests |
| 113 | +# Cyan: < -75% under requests |
| 114 | +``` |
| 115 | + |
| 116 | +## 📊 Example Output |
| 117 | + |
| 118 | +``` |
| 119 | +Processing 3 running pods... |
| 120 | +Progress: 3/3 pods - Complete! |
| 121 | +
|
| 122 | ++------------------+------------------+-------------+--------------+----------------+-------------+---------------+ |
| 123 | +| POD | REQUESTED MEMORY | USED MEMORY | MEMORY DIFF | REQUESTED CPU | USED CPU | CPU DIFF (%) | |
| 124 | ++------------------+------------------+-------------+--------------+----------------+-------------+---------------+ |
| 125 | +| nginx-deployment | 128.0Mi | 45.2Mi | -64.69% | 100m | 23m | -77.00% | |
| 126 | +| api-server | 512.0Mi | 634.1Mi | 23.85% | 200m | 156m | -22.00% | |
| 127 | +| database | 1.0Gi | 890.3Mi | -13.18% | 500m | 520m | 4.00% | |
| 128 | ++------------------+------------------+-------------+--------------+----------------+-------------+---------------+ |
| 129 | +``` |
| 130 | + |
| 131 | +## 🛠️ Command Line Options |
| 132 | + |
| 133 | +| Flag | Description | |
| 134 | +|------|-------------| |
| 135 | +| `-n <namespace>` | Specify namespace to check (defaults to current context) | |
| 136 | +| `-a` | Check all namespaces | |
| 137 | +| `-o <filter>` | Filter output to 'cpu' or 'memory' | |
| 138 | +| `-d` | Only show pods with usage over requests | |
| 139 | +| `-i, --ignore-unset` | Ignore pods without resource requests set | |
| 140 | +| `--context <context>` | Use specific kubeconfig context | |
| 141 | +| `-h` | Show help message | |
| 142 | +| `--color-red <float>` | Threshold for red color (default: 0.0) | |
| 143 | +| `--color-yellow <float>` | Threshold for yellow color (default: -20.0) | |
| 144 | +| `--color-cyan <float>` | Threshold for cyan color (default: -90.0) | |
| 145 | + |
| 146 | +## 🤝 Contributing |
| 147 | + |
| 148 | +Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change. |
| 149 | + |
| 150 | +1. Fork the repository |
| 151 | +2. Create your feature branch (`git checkout -b feature/AmazingFeature`) |
| 152 | +3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) |
| 153 | +4. Push to the branch (`git push origin feature/AmazingFeature`) |
| 154 | +5. Open a Pull Request |
| 155 | + |
| 156 | +## 📝 License |
| 157 | + |
| 158 | +This project is licensed under the GNU GPL V3 License - see the [LICENSE](LICENSE) file for details. |
| 159 | + |
| 160 | +## ☕ Support |
| 161 | + |
| 162 | +If you find this tool helpful, consider supporting the development: |
| 163 | + |
| 164 | +<div align="center"> |
| 165 | + |
| 166 | +[](https://ko-fi.com/senk0) |
| 167 | + |
| 168 | +</div> |
| 169 | + |
| 170 | +## 🐛 Troubleshooting |
| 171 | + |
| 172 | +### Common Issues |
| 173 | + |
| 174 | +**"Error connecting to metrics API"** |
| 175 | +- Ensure `metrics-server` is installed: `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml` |
| 176 | +- Check if metrics-server pods are running: `kubectl get pods -n kube-system | grep metrics-server` |
| 177 | + |
| 178 | +**"No running pods found"** |
| 179 | +- Verify you're connected to the right cluster: `kubectl cluster-info` |
| 180 | +- Check if pods exist in the namespace: `kubectl get pods -n <namespace>` |
| 181 | + |
| 182 | +**"Error creating kubeconfig"** |
| 183 | +- Ensure your kubeconfig file exists and is valid: `kubectl config view` |
| 184 | +- Try specifying a different context: `kdiff --context <context-name>` |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +<div align="center"> |
| 189 | + |
| 190 | +**Made with ❤️ for the Kubernetes community** |
| 191 | + |
| 192 | +[Report Bug](https://github.com/Senk02/kdiff/issues) · [Request Feature](https://github.com/Senk02/kdiff/issues) |
| 193 | + |
| 194 | +</div> |
0 commit comments