forked from jordanwilson230/kubectl-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubectl-ip
executable file
·35 lines (26 loc) · 1.44 KB
/
kubectl-ip
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
#!/bin/bash
pod=$1
i=0
nodes=($(kubectl get pod -lapp=${pod} -o json | jq -r '.items[] | .spec.nodeName'))
[[ "${nodes[@]}" ]] && label='app'
if [[ -z "${nodes[@]}" ]] ; then
nodes=($(kubectl get pod -lcomponent=${pod} -o json | jq -r '.items[] | .spec.nodeName'))
[[ "${nodes[@]}" ]] && label='component'
fi
if [[ -z "${nodes[@]}" ]] ; then
nodes=($(kubectl get pod -lname=${pod} -o json | jq -r '.items[] | .spec.nodeName'))
[[ "${nodes[@]}" ]] && label='name'
fi
[[ -z "${nodes[@]}" ]] && echo -e "\nNo match while searching through labels: app, name, or component for $1\n" && exit 1
pods=($(kubectl get pod -l${label}=${pod} -o json | jq -r '.items[] | .spec.hostname'))
clear
echo -e "\n__________________________________________________________________________________________ \n| POD | LOCATION | NODE IP | POD_IP |"
echo -e "|------------------------------------------------------------------------------------------"
count=0
for node in ${!nodes[@]}; do
node_ip=$(kubectl get node ${nodes[$node]} -o json | jq -r '.status.addresses' | jq -r '.[] | select(.type=="ExternalIP").address')
pod_ip=$(kubectl get po -l${label}=$1 -o json | jq -r '.items['$i'].status.podIP')
echo -e "| ${pods[$node]} ${nodes[$node]} $node_ip $pod_ip"
let i=i+1
done
echo -e "|__________________________________________________________________________________________\n"