Reputation: 15750
Folks, Is there an easier method to grab the external ip address of a service in Kubernetes, than to parsing the output of a kubectl output?
kubectl get services/foo --namespace=foo -o json
Thanks!
Upvotes: 3
Views: 3604
Reputation: 925
Using kubectl is the easiest way to get the ingress IP addresses of your services. If you are looking to get just the IP addresses then you can do most of the parsing as part of the kubectl command itself.
kubectl get svc foo -n foo \
-o jsonpath="{.status.loadBalancer.ingress[*].ip}"
This may not apply to you but some cloud load balancers (like AWS ELB) give you a hostname rather than IP address so you will need to look for that instead.
kubectl get svc foo -n foo \
-o jsonpath="{.status.loadBalancer.ingress[*].hostname}"
You can get both by using the jsonpath union operator if you like.
kubectl get svc foo -n foo \
-o jsonpath="{.status.loadBalancer.ingress[*]['ip', 'hostname']}"
If you want a human readable output you can use the custom-columns
output format.
kubectl get svc foo -n foo \
-o custom-columns="NAME:.metadata.name,IP ADDRESS:.status.loadBalancer.ingress[*].ip"
Upvotes: 11
Reputation: 5736
Can't you just use jq
to do something like
kubectl get services/foo --namespace=foo -o json| jq '.items[0].status.hostIP'
https://stedolan.github.io/jq/
Upvotes: 1