get all the proper namespaces and ingressroutes with the python k8's api client library

3/4/2021

I have the following command line below. It gives me the namespaces and ingressroutes names (see the Example below)

kubectl --context mlf-eks-dev get --all-namespaces ingressroutes

Example

NAMESPACE                       NAME                                                           AGE
aberdeentotalyes               aberdeentotalgeyes-yesgepi                                      98d

I"m trying to replicate the kubetl command line above through my python code, using the python client for kubernetes but I miss on the option, on how to get the ingressroutes.

#My python code
from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
    print("%s\t%s" % (i.metadata.namespace, i.metadata.name))

The results are below

wwwpaulolo   ci-job-backup-2kt6f
wwwpaulolo   wwwpaulolo-maowordpress-7dddccf44b-ftpbq
wwwvhugo        ci-job-backup-dz5hs
wwwvhugo        wwwvhua-maowordpress-5f7bdfdccd-v7kcx

I have the namespaces but not the ingressroutes, as I don't know how can I get it.

Question is what is the option to have the ingressroutes, please?

Any helps are more than welcomed.

Cheers

-- Andy K
kubectl
kubernetes
kubernetes-ingress
python
python-3.x

2 Answers

3/5/2021

After a careful reading of the documentation of the existing APIs for ingressroutes, I found none that can be used, all of them are still in beta as Ingressroutes is not a native components of Kubernetes.

I also asked on Slack's Kubernetes, on the Kubernetes client channel.

Alan C on Kubernetes's slack, gave me that answer:

There's no class for ingressroutes. You can use the dynamic client to support arbitrary resource types (see link)

My solution is to use the python library subprocess to run the kubectl command line.

-- Andy K
Source: StackOverflow

7/9/2021

did you try CustomObjectsApi?

from kubernetes import client, config
config.load_kube_config()
api = client.CustomObjectsApi()
dir(api) # check for list_cluster_custom_object 

#example below api will list all issuers in the cluster. 
#issuer is custom resource of cert-manager.io
api.list_cluster_custom_object(group="cert-manager.io",
version="v1",plural="issuers")
-- Sandeep kumar singh
Source: StackOverflow