Get Ingress gateway IP address using Kubernetes Python client

7/3/2021

I am using the following kubectl command to get the Ingress host IP address after my Seldon Deployment is avaible.

kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}'

I would like to run the same command from the Kubernetes Python API but cannot find any information in the documentation on how to do so.

Could you please help me out?

Thanks in advance.

-- Yannick
kubernetes
kubernetes-ingress
kubernetes-python-client
python
seldon-core

2 Answers

7/3/2021

There's a separate client function for each REST operation on each Kubernetes object type. Once you have that object, you can navigate it like any other Python object.

service = kubernetes.client.read_namespaced_service('istio-ingressgateway', 'istio-system')
print(service.status.load_balancer.ingress[0].ip)
# Note the capitalization ^^^^ of load_balancer, not loadBalancer

The service object is a V1Service object. More generally, the API documentation includes every method call and documentation for all of the request and return types.

A Service is a standard Kubernetes object. If you were dealing with some of the Istio-specific objects like VirtualServices, there is a separate API for custom resources.

-- David Maze
Source: StackOverflow

2/18/2022
import kubernetes

network_api =kubernetes.client.NetworkingV1Api()
service = network_api.read_namespaced_ingress(ingress_name, namespace)
print(service.status.load_balancer.ingress[0].ip)
-- Vitaliy Novakivskiy
Source: StackOverflow