Cloud Technology

How do I fix the "connection to the server localhost:8080 was refused" error in Kubernetes?

TH Asked by Thomas Miller · 10-11-2025
0 upvotes 18,522 views 0 comments
The question

I just installed kubectl and I am trying to run my first command like 'kubectl get nodes', but I keep getting an error saying "The connection to the server localhost:8080 was refused - did you specify the right host or port?". I haven't manually configured a server on port 8080, so I'm confused why kubectl is looking there by default. Is there a missing configuration file or an environment variable I need to set so that it points to my actual cluster API server instead of localhost?

3 answers

0
PA
Answered on 12-11-2025

This error occurs because kubectl cannot find a valid configuration file (the kubeconfig) and is defaulting to localhost:8080 as a last resort. To fix this, you need to ensure that your cluster configuration is located at ~/.kube/config. If you are using a tool like Minikube or an managed service like EKS, you usually need to run a command to generate this file. For example, in Minikube, running minikube start should set this up for you automatically. If you already have the file elsewhere, you can set the environment variable by running export KUBECONFIG=/path/to/your/config. Once the tool knows where your actual API server is located (usually on port 6443, not 8080), the commands will start working immediately.

0
ST
Answered on 14-11-2025

I checked my ~/.kube/ directory and the config file is definitely there, but I am still getting the localhost:8080 error. Could it be a permissions issue with the folder, or is it possible that the context inside the config file is set incorrectly? I'm on a Linux machine and I used sudo to install most of the tools.

RI 15-11-2025

Steven, if you used sudo to create the config, your current user might not have permission to read it. Try running sudo chown -R $USER:$USER ~/.kube. Also, check the content of the file with kubectl config view. If the "server" field under the current context still says localhost:8080, you’ll need to update it to point to your master node's IP. This is a common Software Development hurdle when shifting between local and remote environments—the context must always match the active cluster's endpoint.

0
LI
Answered on 17-11-2025

Sometimes this happens because the Docker Desktop Kubernetes engine isn't fully started yet. Ensure your cluster status is 'Running' before executing kubectl commands.

TH 18-11-2025

I agree with Linda. In my experience with Cloud Technology on local machines, we often forget that the API server is a container itself. If the container runtime hasn't finished booting up the control plane, kubectl has nowhere to go and defaults back to that 8080 error.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session