FileNotFoundError: [Errno 2] No such file or directory: '/root/.kube/config' but file exists

8/21/2018

I am trying to build a kubernetes python app using a docker container but keep getting this error.

if os.getenv('KUBERNETES_SERVICE_HOST'):
    config.load_incluster_config()
else:
    config.load_kube_config()

However, the file exists

-- clout_chaser
docker
kubernetes
minikube
python

1 Answer

8/22/2018

Where is the .kube/config file? in host directory or in container ?

As far as I know, in a container we normally use the incluster_config to connect to the api server, if we have the env KUBERNETES_SERVICE_HOST configured, which injected into the pod by kubelet automatically. So try to setup the env KUBERNETES_SERVICE_HOST when you start the container.

-- Kun Li
Source: StackOverflow