简体   繁体   中英

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 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

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);

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