Skip to content
Advertisement

Can’t connect to kubernetes API from inside the cluster

I’m trying to use the fabric8io/kubernetes-client in a simple example on my local minikube cluster where I get an IP of a pod

JavaScript

some-pod-name-jnfen3 is a name of a pod which finished execution and visible if I execute kubectl get pods.

https://localhost:32780/ is a kubernetes API host which I get from kubectl config view -o jsonpath="{.clusters[?(@.name=="minikube")].cluster.server}".

  • minikube has only 1 node.
  • fabric8io/kubernetes-client version is 4.9.1
  • Java 11

I deploy this code as a Job on the same cluster as the some-pod-name-jnfen3. Here’s the Exception:

JavaScript

For some reason it can’t connect to the kubernetes API host.

How can I fix it?

UPDATE

If I don’t pass the config to the client, it gets the correct master IP and then fails with the following exception

JavaScript

Advertisement

Answer

kubectl config view -o jsonpath="{.clusters[?(@.name=="minikube")].cluster.server}" returns the relative IP. It is different for the Pod.

Not passing config will make the library find the correct IP.

Also a new service account should be created and set in the job.yaml.

The default service account doesn’t have permissions to fetch k8s entities.

Related GitHub issue

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement