简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM