mirror of
https://gitlab.kube.huskypup.net/Scooby/Homelabv4.git
synced 2026-08-21 11:36:50 +00:00
47 lines
1.7 KiB
Bash
Executable File
47 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
||
# Health check script for Kubernetes cluster
|
||
|
||
echo "======================================"
|
||
echo " Kubernetes Cluster Health Check"
|
||
echo "======================================"
|
||
echo ""
|
||
|
||
echo "=== Node Resources ==="
|
||
kubectl top nodes 2>&1 || echo "❌ Metrics server not working!"
|
||
echo ""
|
||
|
||
echo "=== High Memory Nodes (>85%) ==="
|
||
kubectl top nodes --no-headers | awk '$5 > 85 {print "⚠️ "$1" - "$5"% memory"}'
|
||
echo ""
|
||
|
||
echo "=== Pods without Resource Limits ==="
|
||
COUNT=$(kubectl get pods -A -o json | jq -r '.items[] | select(.spec.containers[].resources.limits == null) | .metadata.namespace + "/" + .metadata.name' 2>/dev/null | wc -l)
|
||
echo "$COUNT pods without resource limits"
|
||
echo ""
|
||
|
||
echo "=== Failing Pods ==="
|
||
kubectl get pods -A --field-selector=status.phase!=Running,status.phase!=Succeeded 2>/dev/null | grep -v "No resources found" || echo "✅ All pods running"
|
||
echo ""
|
||
|
||
echo "=== HPA Status ==="
|
||
kubectl get hpa -A 2>/dev/null | grep -v "No resources found" || echo "ℹ️ No HPAs configured"
|
||
echo ""
|
||
|
||
echo "=== Pods with High Restarts (>10) ==="
|
||
kubectl get pods -A -o json | jq -r '.items[] | select(.status.containerStatuses != null) | select(.status.containerStatuses[].restartCount > 10) | .metadata.namespace + "/" + .metadata.name + " - " + (.status.containerStatuses[].restartCount|tostring) + " restarts"' 2>/dev/null || echo "✅ No pods with excessive restarts"
|
||
echo ""
|
||
|
||
echo "=== Storage Status ==="
|
||
kubectl get pv | grep -c "Bound"
|
||
echo "persistent volumes bound"
|
||
echo ""
|
||
|
||
echo "=== Ingress Status ==="
|
||
kubectl get ingress -A | tail -n +2 | wc -l
|
||
echo "ingresses configured"
|
||
echo ""
|
||
|
||
echo "======================================"
|
||
echo " Health Check Complete"
|
||
echo "======================================"
|