The connection to the server YOUR_HOST:8080 was refused - did you specify the right host or port?
Routes kubectl connection-refused-to-loopback failures. Use when kubectl tries YOUR_HOST:8080, which means no kubeconfig was loaded. Not for refusals on a real cluster address (check the server field) or TLS errors.
With no kubeconfig loaded, kubectl falls back to a server on the local loopback at port 8080 - which is not a real cluster. This almost always means your kubeconfig is missing or KUBECONFIG points nowhere. Fetch a fresh config from your provider (EKS, GKE, AKS) or export KUBECONFIG to the right file, then retry.
The error
The connection to the server YOUR_HOST:8080 was refused - did you specify the right host or port?What to do
- Confirm nothing is loaded:
kubectl config view --minifyExpected: Empty clusters/contexts/users, or an error - no config is active.
- Find the gap:
echo $KUBECONFIG
ls -la ~/.kube/configExpected: Shows the unset variable or the missing file.
- Rebuild the config, e.g.:
aws eks --region [region] update-kubeconfig --name [cluster](GKE: gcloud container clusters get-credentials [cluster] --region [region]; AKS: az aks get-credentials ...) Expected: Context added to ~/.kube/config.
- Verify:
kubectl get nodesExpected: Node list, no connection error.
When this applies
- the exact YOUR_HOST:8080 connection refused message
- fresh shells where KUBECONFIG was set in another shell
- sudo runs that lose the user's env and home
When it does NOT apply
- connection refused on a real cluster IP or hostname (cluster or network is down)
- certificate or auth errors (config loaded, creds bad)
Works with
all kubectl versions
The connection to the server [real-host]:6443 was refused
Same words, real address: the cluster itself is unreachable. Check the API server and network instead of the kubeconfig.
Why it happens
kubectl's default server is the loopback on port 8080 when no kubeconfig provides a cluster entry. Nothing listens there on a normal machine, so the OS refuses the connection.
Edge cases
- Running kubectl with sudo uses root's home and env, so your user's ~/.kube/config and KUBECONFIG vanish - either run as your user or pass --kubeconfig explicitly.
- On a kubeadm-built cluster, copying /etc/kubernetes/admin.conf to ~/.kube/config as your user fixes this permanently.
Resolved from
gh:tmatin100/troubleshoot (aws/eks troubleshooting doc) - https://github.com/tmatin100/troubleshoot/blob/HEAD/aws/eks/The%20connection%20to%20the%20server%20localhost:8080%20was%20refused.md
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.