Skip to content

Instantly share code, notes, and snippets.

@jk
Created December 19, 2024 14:11
Show Gist options
  • Save jk/f3a4d93bbe6aa4dd846d571081252fe8 to your computer and use it in GitHub Desktop.
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
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