Created
December 19, 2024 14:11
-
-
Save jk/f3a4d93bbe6aa4dd846d571081252fe8 to your computer and use it in GitHub Desktop.
Kubernetes: Show all load balancer object types with it external IP and ports for a given or all namespaces
This file contains hidden or 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
klbs() { | |
local namespace_flag | |
if [ -n "$1" ]; then | |
namespace_flag="-n $1" # Set -n <namespace>, if a namespace was given | |
else | |
namespace_flag="--all-namespaces" # Default: Show all namespaces | |
fi | |
{ | |
printf "NAMESPACE\tNAME\tEXTERNAL-IP\tPORT(S)\n" | |
kubectl get services $namespace_flag \ | |
-o jsonpath='{range .items[?(@.spec.type=="LoadBalancer")]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{.status.loadBalancer.ingress[0].ip}{"\t"}{range .spec.ports[*]}{.port}{", "}{end}{"\n"}{end}' \ | |
| sed 's/, $//' | |
} | column -s $'\t' -t | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment