interact with API added by k8s operator using native k8s python client

9/12/2019

It's possible to talk to k8s's API, for instance talking to CoreV1Api:

from kubernetes import client, config
v1 = client.CoreV1Api()
k8s_corev1_api = client.CoreV1Api()
k8s_corev1_api.read_namespaced_service("myservice", 'default')

If I add an operator to k8s, for instance redis-operator, this operator adds an API endpoint redisfailover to k8s. Is it possible to interact with it using native k8s Python client?

-- JACK M
kubernetes
python

1 Answer

9/24/2019

Yes, redisfailover is actually a Custom Resource, created by the Redis Operator. You can interact with custom resources with the CustomObjectsApi, very similarly to your above example:

api = client.CustomObjectsApi()
api.get_namespaced_custom_object(
    group='databases.spotahome.com',
    version='v1',
    namespace='default',
    plural='redisfailovers',
    name='myredisfailover'
)
-- gnvk
Source: StackOverflow