Kubectl is not working on AWS EC2 instance

5/9/2018

I am unable to install kubectl on AWS ec2 instance(Amazon ami and ubuntu).

After installing kops and kubectl tried to check the version of kubectl but it is throwing the error:

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

I have already opened the ports, but still, I'm getting the same error.

I have installed Minikube also, but still, I am facing the same issue.

-- Rakesh Sivagouni
amazon-ec2
amazon-web-services
kubectl
kubernetes

3 Answers

2/29/2020

If you want to run with cluster, You should try after getting token by kubeadm init, which gives advice that

-run:

sudo cp /etc/kubernetes/config $HOME/

sudo chown $(id -u):$(id -g) $HOME/config

export KUBECONFIG=$HOME/config

~/.kube/config is your missing file.

-- dose
Source: StackOverflow

5/9/2018

Kubectl is the tool to control your cluster. It can be installed by Kops, for example.

If you already have the cluster to manage it from the host you did not use for the initialization, you should export your Kubeconfig by kops export kubecfg command on the node where you have the configured installation of kops.

If not, initialize the cluster first, and Kops will setup the Kubectl configuration for you automatically.

-- Anton Kostenko
Source: StackOverflow

2/24/2020

This is because your ~/.kube/config file is not correct. Configure it correctly so that you can connect to your cluster using kubectl.

-- Madeesha Fernando
Source: StackOverflow