Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 294
djamaile Avatar asked Dec 31 '22 03:12

djamaile


1 Answers

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.

like image 82
Moshe Shitrit Avatar answered Jan 04 '23 02:01

Moshe Shitrit