Last active
February 19, 2021 05:53
-
-
Save manjumaikan/ec8c5e019a084b7d1f6adebfaff91915 to your computer and use it in GitHub Desktop.
Get all the ports exposed by the nodes of kubernetes cluster deployed on AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get nodes -o json | jq -r .items[].metadata.name | xargs -I{} aws ec2 describe-instances --filters Name=private-dns-name,Values={} | jq -r '[.Reservations[].Instances[].SecurityGroups[].GroupId] | @csv' | sed 's/"//g' | while read line; do echo $line | tr ',' '\n' | xargs -I{} aws ec2 describe-security-groups --filter Name=group-id,Values={} | jq -Sr '.SecurityGroups[] | [.IpPermissionsEgress[] |[.FromPort, .ToPort]],[.IpPermissions[] |[.FromPort, .ToPort]] | @json';done | sort | uniq | sed 's/\([0-9]\),\(-\?[0-9]\)/\1\ - \2/g' | tr ',' '\n' | sed '/null/d' | tr -s '[' | tr -s ']' | sort | uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment