kubectl: The connection to the server localhost:8080 was refused — did you specify the right host or port?
kubectl has no usable kubeconfig, so it falls back to localhost:8080 — or the cluster API server is unreachable.
Meaning
localhost:8080 almost always means “no kubeconfig found” (KUBECONFIG unset, wrong user, or running with sudo). Other hosts in the message mean the API server is down or blocked, or your credentials expired (“You must be logged in to the server (Unauthorized)”).
Common causes
- No ~/.kube/config for this user (or sudo uses root’s home)
- KUBECONFIG pointing to a missing file
- Wrong current context
- API server down / VPN not connected
- Expired cloud credentials (EKS/GKE/AKS tokens)
⚡ Quick fix
kubectl config get-contextsandkubectl config use-context …- Regenerate kubeconfig (
aws eks update-kubeconfig,gcloud container clusters get-credentials,az aks get-credentials) - Don’t run kubectl with sudo
- k3s/kubeadm: copy
/etc/rancher/k3s/k3s.yamlor/etc/kubernetes/admin.confto ~/.kube/config
Detailed fix by platform
Kubernetes
- Check which config is used:bash
echo $KUBECONFIG kubectl config view --minify kubectl config get-contexts aws eks update-kubeconfig --name prod-cluster --region ap-south-1
How to diagnose
- Host in message — localhost:8080 (no config) or a real API endpoint?
- Context — Current context correct?
- Credentials — Expired token?
- Network — VPN / firewall to the API server?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026