-
Notifications
You must be signed in to change notification settings - Fork 1
/
eck_pods_1.sh
executable file
·188 lines (173 loc) · 7.09 KB
/
eck_pods_1.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
# count of array
count=`jq '.items | length' "${1}"`
if [ ${count} = 0 ]; then
exit
fi
echo "========================================================================================="
echo "ITEMS TO NOTES:"
echo " - Volume Claims template must be named elasticsearch-data or else you can have data loss"
echo " - Don’t use emptyDir as data volume claims - it might generate permanent data loss."
echo " - Look at the READY to see is all are ready - if not then focus on that pod"
echo " - Look at individual pod for Affinities to troubleshoot if pod are having issues scheduleing"
echo "========================================================================================="
echo ""
echo ""
echo "========================================================================================="
echo "Summary"
echo "========================================================================================="
echo ""
jq -r '
def count(stream): reduce stream as $i (0; .+1);
[.items
| sort_by(.metdata.name)[]
| {
"NAME": (.metadata.name // "-"),
"READY": ((count (.status.containerStatuses[] | select (.ready==true))|tostring) + "/" + (count (.status.containerStatuses[] | select (.started==true))|tostring) // "-"),
"READY STATUS": (.status.conditions[] | select (.type=="Ready") | .status // "-"),
"RESTARTS": ([.status.containerStatuses[].restartCount]|add // "-"),
"LAST STARTTIME": (.status.startTime // "-"),
"NODE": (.spec.nodeName // "-"),
"CREATED": (.metadata.creationTimestamp // "-")
}]| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
echo "========================================================================================="
echo "Summary - wide with more details"
echo "========================================================================================="
echo ""
jq -r '
[.items
| sort_by(.metdata.name)[]
| {
"NAME": (.metadata.name // "-"),
"IP": (.status.podIP // "-"),
"PHASE" : (.status.phase // "-"),
"apiVersion": (.metadata.ownerReferences[] | select(.controller==true) |.apiVersion // "-"),
"OWNER": (.metadata.ownerReferences[] | select(.controller==true) |.kind + "/" + .name // "-"),
"CONTAINERS": ([.spec.containers[].name]|join(",") // "-"),
"IMAGES": ([.spec.containers[].image]|join(",") // "-")
}]| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
#
# STATUS TABLE
echo "========================================================================================="
echo "Status"
echo "========================================================================================="
echo ""
jq -r '
[.items
| sort_by(.metadata.name)[]
| {
"NAME": (.metadata.name // "-"),
"STATUS": (.status.phase // "-"),
"READY": (.status.conditions[] | select(.type=="Ready") | .status // "-"),
"CONTAINERS READY": (.status.conditions[] | select(.type=="ContainersReady") | .status // "-"),
"INITALIZED": (.status.conditions[] | select(.type=="Initialized") | .status // "-"),
"POD SCHEDULED": (.status.conditions[] | select(.type=="PodScheduled") | .status // "-"),
"QoS Class": (.status.qosClass // "-"),
}
]
| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
echo "========================================================================================="
echo "SPEC"
echo "========================================================================================="
echo ""
jq -r '
[.items
| sort_by(.metdata.name)[]
| {
"NAME": (.metadata.name // "-"),
"PRIORITY": (.spec.priority // "-"),
"RESTART POLICY": (.spec.restartPolicy // "-"),
"SERVICE ACCT": (.spec.serviceAccount // "-"),
"SCHEDULER": (.spec.schedulerName // "-"),
"SECURITY CONTEXT": ((.spec.securityContext| (to_entries[] | "\(.key)=\(.value)") | select(length >0)) // "-"),
"AFFINITY": ((.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[].podAffinityTerm.labelSelector.matchLabels|(to_entries[] | "\(.key)=\(.value)"))? // "-"),
"SERVICE LINKS": (.spec.enableServiceLinks|tostring // "-")
}]| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
echo "========================================================================================="
echo "Tolerations"
echo "========================================================================================="
echo ""
# FIX - format a bit better
jq -r '
[.items[]
| { "NAME": .metadata.name} +
(.spec.tolerations[] |{
"KEY": (.key // "-"),
"OPERATOR": (.operator // "-"),
"EFFECT": (.effect // "-"),
"TOLERATION": (.tolerationSeconds // "-")
})]| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
# FIX - format a bit cleaner
echo "========================================================================================="
echo "Volumes"
echo "========================================================================================="
echo ""
echo "== PVC"
jq -r '["NAME","VOLUME NAME","CLAIM NAME"],
(.items[] | .metadata.name as $podname
| (.spec.volumes[]
| select(.persistentVolumeClaim != null)
| [ $podname,
(.name // "-"),
(.persistentVolumeClaim.claimName // "-")]))
| join(",")
' "${1}" 2>/dev/null | column -t -s ","
echo ""
echo "== Secrets"
jq -r '["NAME","SECRET","NAME","DEFAULT MODE","OPTIONAL"],
(.items[] | .metadata.name as $podname
| (.spec.volumes[]
| select(.secret != null)
| [ $podname,
(.name // "-"),
(.secret.name // "-"),
(.secret.defaultMode|tostring // "-"),
(.secret.optional|tostring // "-")]))
| join(",")
' "${1}" 2>/dev/null | column -t -s ","
echo ""
echo "== ConfigMaps"
jq -r '["NAME","CONFIG MAP","NAME","DEFAULT MODE","OPTIONAL"],
(.items[] | .metadata.name as $podname
| (.spec.volumes[]
| select(.configMap != null)
| [ $podname,
(.name // "-"),
(.configMap.name // "-"),
(.configMap.defaultMode|tostring // "-"),
(.configMap.optional|tostring // "-")]))
| join(",")
' "${1}" 2>/dev/null | column -t -s ","
echo ""
echo "== emptyDir"
jq -r '["NAME","EMPTYDIR NAME"],
(.items[] | .metadata.name as $podname
| (.spec.volumes[]
| select(.emptyDir != null)
| [ $podname,
(.name // "-")]))
| join(",")
' "${1}" 2>/dev/null | column -t -s ","
echo ""
echo "========================================================================================="
echo "Labels & Annotations"
echo "========================================================================================="
echo ""
for ((i=0; i<$count; i++))
do
item=`jq -r '.items['${i}'].metadata.name' "${1}"`
echo "==== ${item} ----------------------------------------------------------------------------"
echo ""
echo "== Annotations:"
#jq -r '.items['${i}'].metadata.annotations | to_entries | .[] | "* \(.key)",(.value | if try fromjson catch false then fromjson else . end)," "' "${1}" 2>/dev/null
jq -r '.items['${i}'].metadata.annotations | (to_entries[] | "\(.key)=\(.value)")' "${1}" 2>/dev/null
echo ""
echo "== Labels:"
jq -r '.items['${i}'].metadata.labels | (to_entries[] | "\(.key)=\(.value)") | select(length >0)' "${1}" 2>/dev/null
echo ""
done