2022-07-25 02:29:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
dns(){
|
|
|
|
clear -x
|
|
|
|
echo "Generating DNS Names.."
|
2022-09-01 04:32:13 +00:00
|
|
|
# Ignore svclb
|
|
|
|
dep_ignore='svclb-'
|
2022-07-25 02:29:58 +00:00
|
|
|
|
|
|
|
# Pulling pod names
|
2022-09-01 04:32:13 +00:00
|
|
|
k3s crictl pods --namespace ix -s Ready | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//' | grep -Ev -- "$dep_ignore" | sed '1d' >> dns_file
|
|
|
|
mapfile -t ixName < <(< dns_file awk '{print $4}' | sort -u )
|
2022-07-25 02:29:58 +00:00
|
|
|
|
|
|
|
# Pulling all ports
|
|
|
|
all_ports=$(k3s kubectl get service -A)
|
|
|
|
|
|
|
|
clear -x
|
|
|
|
count=0
|
2022-09-01 04:32:13 +00:00
|
|
|
for i in "${ixName[@]}"
|
2022-07-25 02:29:58 +00:00
|
|
|
do
|
|
|
|
[[ count -le 0 ]] && echo -e "\n" && ((count++))
|
2022-09-01 04:32:13 +00:00
|
|
|
appName=$(grep -E "\s$i\s" "dns_file" | awk '{print $3}' | sed 's/-[^-]*-[^-]*$//' | sed 's/-0//' | head -n 1)
|
2022-07-25 02:29:58 +00:00
|
|
|
port=$(echo "$all_ports" | grep -E "\s$appName\s" | awk '{print $6}' | grep -Eo "^[[:digit:]]+{1}")
|
2022-09-01 04:32:13 +00:00
|
|
|
echo -e "$appName $appName.$i.svc.cluster.local $port"
|
2022-09-01 04:36:55 +00:00
|
|
|
done | nl -s ") " -b t | sed '0,/\s\s\s/{s/\s\s\s/- ---- -------- ----/}'| column -t -N "#,Name,DNS_Name,Port"
|
2022-09-01 04:32:13 +00:00
|
|
|
rm dns_file
|
2022-07-25 02:29:58 +00:00
|
|
|
}
|
|
|
|
export -f dns
|