Skip to content

Instantly share code, notes, and snippets.

@manjumaikan
Last active February 19, 2021 05:53
Show Gist options
  • Save manjumaikan/ec8c5e019a084b7d1f6adebfaff91915 to your computer and use it in GitHub Desktop.
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
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