2

I have a Java service that uses the Fabric8 Kubernetes Java Client to connect to a Kubernetes cluster. When I run the service locally using java -jar, it works perfectly. However, when I build a Docker image and run the container, I get the following errors:

Did not find Kubernetes config at: [/root/.kube/config]. Ignoring. Trying to configure client from service account... Did not find service account ca cert at: [/var/run/secrets/kubernetes.io/serviceaccount/ca.crt}]. Could not find the service account token at the default location: [/var/run/secrets/kubernetes.io/serviceaccount/token]. Ignoring. Trying to configure client namespace from Kubernetes service account namespace path... Did not find service account namespace at: [/var/run/secrets/kubernetes.io/serviceaccount/namespace]. Ignoring.

My Setup:Using MiniKube, Running the service using java -jar my-service.jar works as expected Running the same service as a Docker container results in the above errors

Troubleshooting Done: Inside the container, I ran cat /root/.kube/config and verified that the config file exists and has the expected content.

Explicitly set the KUBECONFIG environment variable inside the container: export KUBECONFIG=/root/.kube/config

Passed the kube config file as a volume while running the Docker container: docker run -v $HOME/.kube:/root/.kube my-service:latest

Questions: Am I missing something in how Docker containers interact with Kubernetes credentials?

The Kubernetes Java Client should use the config file located at /root/.kube/config inside the container and connect to the cluster.

2
  • Can you edit the question to include a minimal reproducible example? It seems like the kubeconfig file isn't actually being found, and seeing the exact docker run -v option would be informative. This may not work, though, since the minikube might embed the context-sensitive 127.0.0.1 address as the API server address. I wouldn't usually try mixing Docker and Kubernetes, though, can you either run this program directly on the host or in a Kubernetes Deployment or Job? Commented Mar 6 at 11:15
  • I have already tested using the java -jar jarname and it was working but when i'm trying to run docker image only it's failing. Commented Mar 6 at 13:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.