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.