kubectl apply command does not work, gives connection refused error

Jibin Mathew picture Jibin Mathew · Jul 26, 2018 · Viewed 17.9k times · Source

when I am trying to setup pod network using the following

sudo kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml

I get this error, please help

unable to recognize "https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused

UPDATE: Doesn't seem to be a permission issue, unlike other question

Answer

Jibin Mathew picture Jibin Mathew · Jul 26, 2018

Found that it's an issue with kubectl not being configured properly.

Fixed the issued by using the following commands for calico network(change accordingly for your network addon plugin)

sudo kubeadm init --pod-network-cidr=192.168.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

and then run

sudo kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml

and follow the rest accordingly