Python Kubernetes Client: equivalent of kubectl get [custom-resource]

5/4/2020

With kubectl I can execute the following command:

kubectl get serviceentries 

Then I receive some information back. But serviceentries is a custom resource. So how do I go about getting the same information back but then with the kubernetes client?

Yaml looks like this for example:

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: external-svc-https
spec:
  hosts:
  - api.dropboxapi.com
  - www.googleapis.com
  - api.facebook.com
  location: MESH_EXTERNAL
  ports:
  - number: 443
    name: https
    protocol: TLS
  resolution: DNS

Anyone know the right method to use?

-- Peter rosevelt
kubernetes
python

2 Answers

5/4/2020

You can't do that unless you have the objects added to the python client, which probably will never be done.

Looks like Istio is working now on Go client, but you can hook up to this issue to keep the track.

There is this example though, that should work. You would need to add the object by yourself.

-- suren
Source: StackOverflow

5/8/2020

you should be able to pull it using the python client like this:

kubernetes.client.CustomObjectsApi().list_cluster_custom_object(group="networking.istio.io", version="v1alpha3", plural="serviceentries")

That method applies to every custom resource within kubernetes and doesn't require any further definition to the python client.

-- Moshe Shitrit
Source: StackOverflow