Author: James Ressler
Date: May 9, 2024
Audience: Everyone
Environmental details: Self-hosted
Issue
When trying to run kubectl
commands on the application server, you see an error like the one below:
E0919 14:57:21.242964 414467 memcache.go:265] couldn’t get current server API group list: Get “http://localhost:8080/api?timeout=32s 78”: dial tcp 127.0.0.1:8080: connect: connection refused
Solution
This is often caused by the $KUBECONFIG
environment variable pointing to the incorrect location or the Kube configuration file being in a different location.
First, check the $KUBECONFIG
environment variable with:
echo $KUBECONFIG
It should return:
/etc/kubernetes/admin.conf
If it returns a different location, you can either set the variable to point to /etc/kubernetes/admin.conf
or make a copy of the admin.conf
file in the location at $KUBECONFIG
.
Change Where $KUBECONFIG
Points
You can temporarily change where the $KUBECONFIG
environment variable points by running:
export KUBECONFIG=/etc/kubernetes/admin.conf
To persist this change, add that command to your shell startup file (e.g. $HOME/.bashrc
).
Copy the admin.conf
File to a New Location
You can move the admin.conf file to a new location with:
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
Then, make sure to export the KUBECONFIG
variable to point to the new location:
export KUBECONFIG=$HOME/.kube/config
To persist this change, add that command to your shell startup file (e.g. $HOME/.bashrc
).
Now, kubectl
commands should work again.
Related to
Comments
0 comments
Please sign in to leave a comment.