I want to use fabric8 kubernetes client (java) inside a pod. How do I obtain the kubernetes client for the cluster it is deployed on?

8/6/2018

I want to use fabric8 kubernetes client (java) inside a pod. How do I obtain the kubernetes client for the cluster it is deployed on?

I can get the configuration for any cluster using the kubeconfig file for that cluster. Is there a way to detect the kubernetes cluster the pod containing the code is deployed on and create an instance of KubernetesClient?

Thanks in advance -RockerArm

-- rockeArm
fabric8
java
kubernetes

1 Answer

8/26/2018

Thanks to Thilo's comment, I was able to test out the blank config and it worked.

The following snippet of code will ensure that the kubernetes client will be created taking in the configuration of the cluster the pod is currently executing in.

    kubeConfig = new ConfigBuilder()
                        .withNamespace("mynamespace")
                        .build();
    kubeClient = new DefaultKubernetesClient(kubeConfig);
-- rockeArm
Source: StackOverflow