Server localhost:8080 was refused

Hi Team,
Recently I started learning Kubernetes, and I am following k8’s course. I have created a aws instance and installed Kubernetes in that instance. When I try to execute the kubectl apply command or other commands like kubectl get pods I am getting below error.
“The connection to the server localhost:8080 was refused - did you specify the right host or port?”
Can you help me to fix this error.
Thanks in advance !!.

Hello, @nagavardhan.awsdevop
Did you perform below steps?

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Hi,
I am getting below error.

ubuntu@master-node:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
cp: cannot stat ‘/etc/kubernetes/admin.conf’: No such file or directory

You’ll have to get the configuration from your Amazon cluster. With the cp command above, you tried to get a non-existing config from your local machine.

Did you install Kubernetes on an EC2 instance, or are you using EKS?

Also, perhaps try setting up Kubernetes on your local machine before trying it out on a remote server? It will make things a little bit easier.

Hi @HerrSubset,
Thanks for resposne.
I have installed Kubernetes on an EC2 instance.
Can you please share any reference document how to set up in my local machine?

You have to copy the kubernetes config from your local cluster into the folder that kubectl uses to store it’s configuration. That way, kubectl gets the necessary credentials and connection info in order to see your cluster.

Usually the kubectl config file is stored at: $Home/.kube/config in the master node of your remote Kubernetes cluster. This is the config file used by the kubectl utility installed in your remote cluster’s master node.

Configure local kubectl to access remote Kubernetes cluster - DEV Community

Go through this guide and let us know if you hit any additional problems.

hi @HerrSubset,

Thanks for providing this. I will follow this and let you know the status.