Skip to content

Instantly share code, notes, and snippets.

View manjumaikan's full-sized avatar

Manju Maikan krishnappa manjumaikan

  • Melbourne, Australia
View GitHub Profile
@manjumaikan
manjumaikan / kube-nodes-secgrps
Last active February 19, 2021 05:53
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