Founding prices until 15 December: 30% off Pro, locked for life. See pricing

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

kubectl: connection to the server localhost:8080 was refused

kubectl found no kubeconfig and fell back to localhost:8080.

Kubernetes

What it means

kubectl reads the cluster address and credentials from a kubeconfig. When it finds none, it tries http://localhost:8080, where nothing listens. The cluster is usually fine: kubectl just doesn't know where it is.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. No kubeconfig for this user (running as another user, or with sudo)

Check:

echo $KUBECONFIG
ls -l ~/.kube/config

Fix: Copy the admin kubeconfig to ~/.kube/config (owned by you), or export KUBECONFIG.

2. The kubeconfig points at the wrong server, context or certificate

Check:

kubectl config view --minify

Fix: Fix the server URL or switch context with kubectl config use-context.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors