Java fabric8 kubernetes client to get the name of the deployed kubernetes pod's cluster

586 Views Asked by At

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

Currently, I can obtain the context using:

KubernetesClient client = new DefaultKubernetesClient();
return client.getConfiguration();

When running locally, I can see the current kubernetes context. However, when it is run on the deployed pod, I am unable to see the kubernetes context.

Why is it not working on the deployed pod? How can I detect the kubernetes cluster the pod is deployed on?

1

There are 1 best solutions below

0
On

Is the pod has permission to access k8s cluster? If not, you should grant permissions to pod's ServiceAccount.

https://kubernetes.io/docs/concepts/security/service-accounts/#assign-to-pod

https://kubernetes.io/docs/reference/access-authn-authz/rbac/#service-account-permissions