最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

devops - Kubernetes Java Client Unable to Find Config When Running as Docker Container - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论