kubernetes -list ingress for all namespaces by REST-Call

10/15/2020

I want to list all ingress-urls on a kubernets cluster for every namespace.

I know it´s possible with:

  1. kubectl -> kubectl get ingress
  2. numerous clients, e.g. for python: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/ExtensionsV1beta1Api.md#list_ingress_for_all_namespaces

For my current situation, a simple REST-Call would be the best solution, but I can´t find any documentation which points me in the right direction. Is there a REST-Endpoint to access above mentioned information on a kubernets cluster?

Thanks in advance.

-- Salfii
kubernetes
kubernetes-ingress
rest

1 Answer

10/15/2020

Yes, you can call the API server to retrieve all ingress rules: https://kubernetes/apis/extensions/v1beta1/ingresses

This url would work within your cluster environment. Replace it with some public IP/Domain when calling it from the outside.

You will need to authenticate using Bearer Token. That token is usually mounted within your Pods at /var/run/secrets/kubernetes.io/serviceaccount/token (there are some exceptions, for example terraform kubernetes backend defaults to not mounting this token). To get the token for external use, you can export it using:

TOKEN=$(kubectl describe secret $(kubectl get secrets \
     | grep ^default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d " ")

Here's some more info (not about ingress, but other REST API calls): https://stackoverflow.com/a/50797128/9423721

-- Markus Dresch
Source: StackOverflow