kubectl Command Does Not Run with Error: "connection refused"

James Ressler
James Ressler
  • Updated

Author: James Ressler

Date: May 9, 2024

Audience: Everyone

Environmental details: Self-hosted


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 connect: connection refused


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:


It should return:


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

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request



Please sign in to leave a comment.