kubectl: The Connection to the Server Was Refused

"The connection to the server localhost:8080 was refused" almost never means your cluster is down — it means kubectl has no kubeconfig and is guessing. Here's why, and the one-line fix.

BytExplorer 5 min read July 17, 2026

You run any command and get:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

The giveaway is localhost:8080. You almost certainly didn't configure a server at that address — that's kubectl's fallback when it can't find a kubeconfig. So this rarely means "the cluster is broken." It means kubectl doesn't know where your cluster is, defaulted to an old insecure port, and found nothing listening there.

Cause 1: No kubeconfig loaded

kubectl reads its cluster address from ~/.kube/config (or whatever KUBECONFIG points at). If that file is missing or empty, you get the localhost:8080 fallback. Check what kubectl thinks it's talking to:

kubectl config current-context     # "error: current-context is not set" = no config

Point kubectl at the right file:

export KUBECONFIG=/path/to/your/kubeconfig
kubectl config current-context     # should now name your cluster

Cause 2: k3s / k3d — the config is root-owned

On a fresh k3s node the kubeconfig lives at /etc/rancher/k3s/k3s.yaml and is only readable by root, so a normal-user kubectl finds nothing. Copy it to your user and export it:

mkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config

(Or just use sudo k3s kubectl ....)

Cause 3: The wrong context is selected

If you have several clusters, you may be pointed at one that isn't running. List them and switch:

kubectl config get-contexts        # * marks the active one
kubectl config use-context my-real-cluster

Cause 4: The cluster really is down

Only after the above — if the context is correct and still refused, the API server may genuinely be off. For a local cluster, confirm it's running (k3s: systemctl status k3s; minikube: minikube status) and start it.

The checklist

  1. See localhost:8080? Suspect missing kubeconfig, not a dead cluster.
  2. kubectl config current-context — is one even set?
  3. Set KUBECONFIG (k3s: copy /etc/rancher/k3s/k3s.yaml to ~/.kube/config).
  4. Multiple clusters? kubectl config use-context <name>.
  5. Only then check whether the API server / cluster is actually running.

Frequently Asked Questions

Why does kubectl say "localhost:8080"?

That's kubectl's fallback address when it can't find a kubeconfig. It almost always means no config is loaded — not that your cluster is down.

Where is the kubeconfig for k3s?

At /etc/rancher/k3s/k3s.yaml (root-owned). Copy it to ~/.kube/config and fix ownership, or just run sudo k3s kubectl.

How do I switch between clusters?

Run kubectl config get-contexts to list them, then kubectl config use-context <name> to select the right one.

Put it into practice

Stop reading, start building

This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.

More in Troubleshooting