Search code examples
kuberneteskubernetes-apiserverkubernetes-custom-resourceskubernetes-python-client

Kubernetes python API get instances of CRD


I'm currently using the Python APIs for Kubernetes and I have to:

  • Retrieve the instance of a custom resource name FADepl.

  • Edit the value of that instance.

In the terminal, I would simply list all FADepls with kubectl get fadepl and then edit the right one using kubectl edit fadepl <fadepl_name>. I checked the K8s APIs for Python but I can't find what I need. Is it something I can do with the APIs?

Thank you in advance!


Solution

  • You're right. Using get_namespaced_custom_object you can retrieve the instance. This method returns a namespace scoped custom object. By default it uses a synchronous HTTP request.

    Since the output of that method returns an object, you can simply replace it using replace_cluster_custom_object.

    Here you can find implementation examples.

    See also whole list of API Reference for Python.