scale-catalog/functions/dns.sh

28 lines
943 B
Bash
Raw Normal View History

2022-07-25 02:29:58 +00:00
#!/bin/bash
dns(){
clear -x
echo "Generating DNS Names.."
# Pulling pod names
2022-09-01 05:10:45 +00:00
k3s crictl pods --namespace ix -s Ready | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//' | grep -v 'svclb-' | sed '1d' >> dns_file
mapfile -t ix_name_array < <(< 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
for i in "${ix_name_array[@]}"
2022-07-25 02:29:58 +00:00
do
[[ count -le 0 ]] && echo -e "\n" && ((count++))
full_app_name=$(grep -E "\s$i\s" "dns_file" | awk '{print $3}' | sed 's/-[^-]*-[^-]*$//' | sed 's/-0//' | head -n 1)
2022-09-01 05:10:45 +00:00
app_name=$(echo "$i" | cut -c 4-)
port=$(echo "$all_ports" | grep -E "\s$full_app_name\s" | awk '{print $6}' | grep -Eo "^[[:digit:]]+{1}")
echo -e "$app_name $full_app_name.$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
}
2022-12-27 11:02:56 +00:00
export -f dns