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
```text
The connection to the server YOUR_HOST:8080 was refused - did you specify the right host or port?
```

## What to do
1. Confirm nothing is loaded:
```bash
kubectl config view --minify
```
   Expected: Empty clusters/contexts/users, or an error - no config is active.
2. Find the gap:
```bash
echo $KUBECONFIG
ls -la ~/.kube/config
```
   Expected: Shows the unset variable or the missing file.
3. Rebuild the config, e.g.:
```bash
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.
4. Verify:
```bash
kubectl get nodes
```
   Expected: 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