kubectl: Connection to server was refused

Rumu picture Rumu · Jun 20, 2016 · Viewed 17.2k times · Source

When I run kubectl run ... or any command I get an error message saying

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

What exactly is this error and how to resolve it?

Answer

OlaB picture OlaB · Jun 20, 2016

I really don't know much about kubectl... But the various reasons you have a connection refused to localhost I know of are as follows

  • 1) Make sure you can resolve and ping your local host with the IP(127.XX.XX.XX) and also "localhost" if using a DNS or host file.

  • 2) Make sure the service trying to access the localhost has enough permissions to run as root if trying to use localhost.

  • 3) Check the ports with netstat and check for the appropriate flags you need amongst the "Plantu" flags, Look up the meaning of each of the flags as it would apply to your situation. If the service you are trying to access on localhost is listening on that port, netstat would let you know.

  • 4) Check if you have admin or management settings in your application that needs permissions to access your localhost in the configuration parameters of your application.

  • 5) According to the statement that says did you specify the right host or port, this means that either your "kubectl" run is not configured to run as localhost instead your primary DNS server hostname or IP, Check what host is configured to run your application and like I said check for the appropriate ports to use, You can use telnet to check this port and further troubleshoot form there.

My two cents!