kubernetes: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined

What happened: I’m using kubeCfg,err := rest.InClusterConfig() for getting the cluster config inside of minikube for the dynamic informer.

//go run main.go

FATA[0000] could not get config                          error="unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined"
exit status 1

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T21:54:15Z", GoVersion:"go1.15", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:43:34Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration: minikube

  • Kernel (e.g. uname -a): Darwin Kernel Version 19.5.0

I found various similar issues related to this but couldn’t find any solution or workaround.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

Thanks, @alejandrox1, and @yliaog. The final changes after a suggestion by @alejandrox1 worked. This is the final working code. Thank you for helping with this, really appreciate it.

This is not a sig-net issue, but its just that your client doesn’t have the metadata passed into it properly can you take a quick look at the docs for https://github.com/kubernetes/client-go and make sure nothing solves it for you ?

The issue is that the internal var/lib/svc account file that is used for In-cluster verification is missing, and you also didn’t provide the env vars, so it just doesn’t know how to auth to th apsiserver