kubectl apply command does not work, gives connection refused error
Basically, when you start Kubernetes you start the services on port 6443, however the above command is searching for services running on port 8080. This is because when you run sudo, it runs using the variable from sudo which doesn't have information about the port on which Kubernetes is running, so it defaults to 8080. Run the following command as root user on the master node.
cp -i /etc/kubernetes/admin.conf $HOME/
Now run the kubectl apply
command as below as root user.
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
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
The following issue leads me to the conclusion that the api-server might not be running.
I recommend to check the status of the kubelet
service on the master node
systemctl status kubelet.service
And check the logs for for more information to see why the api-server is not running and how to fix the problem
journalctl -xn --unit kubelet.service