-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster-info.sh
More file actions
60 lines (54 loc) · 1.77 KB
/
Copy pathcluster-info.sh
File metadata and controls
60 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -e
CLUSTER_NAME="threadit-cluster"
ZONE="europe-west1-b"
# Default: all flags true unless specified
SHOW_NAMESPACES=false
SHOW_PODS=false
SHOW_SERVICES=false
SHOW_DEPLOYMENTS=false
SHOW_RESOURCES_PODS=false
SHOW_RESOURCES_NODES=false
SHOW_HPA=false
if [[ $# -eq 0 ]]; then
SHOW_NAMESPACES=true
SHOW_PODS=true
SHOW_SERVICES=true
SHOW_DEPLOYMENTS=true
SHOW_RESOURCES_PODS=true
SHOW_RESOURCES_NODES=true
SHOW_HPA=true
fi
# Parse flags
while [[ "$#" -gt 0 ]]; do
case $1 in
--namespaces) SHOW_NAMESPACES=true ;;
--pods) SHOW_PODS=true ;;
--services) SHOW_SERVICES=true ;;
--deployments) SHOW_DEPLOYMENTS=true ;;
--resources-pods) SHOW_RESOURCES_PODS=true ;;
--resources-nodes) SHOW_RESOURCES_NODES=true ;;
--hpa) SHOW_HPA=true ;;
--all)
SHOW_NAMESPACES=true
SHOW_PODS=true
SHOW_SERVICES=true
SHOW_DEPLOYMENTS=true
SHOW_RESOURCES_PODS=true
SHOW_RESOURCES_NODES=true
SHOW_HPA=true
;;
*) echo "❌ Unknown flag: $1"; exit 1 ;;
esac
shift
done
# Set project and cluster context
gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE
# Output selected info
$SHOW_NAMESPACES && echo -e "\n🔍 Namespaces:" && kubectl get namespaces
$SHOW_PODS && echo -e "\n📦 Pods in $CLUSTER_NAME:" && kubectl get pods -n $CLUSTER_NAME
$SHOW_SERVICES && echo -e "\n🔁 Services:" && kubectl get svc -n $CLUSTER_NAME
$SHOW_DEPLOYMENTS && echo -e "\n📂 Deployments:" && kubectl get deployments -n $CLUSTER_NAME
$SHOW_RESOURCES_PODS && echo -e "\n📊 Resource Usage (Pods):" && kubectl top pods -n $CLUSTER_NAME
$SHOW_RESOURCES_NODES && echo -e "\n🖥️ Resource Usage (Nodes):" && kubectl top nodes
$SHOW_HPA && echo -e "\n📌 Horizontal Pod Autoscalers:" && kubectl get hpa -n $CLUSTER_NAME