Troubleshooting kubectl connection refused
This document describes steps to troubleshoot kubectl error:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Troubleshooting steps below:
- The kubectl should be executed on the Master Node.
- The current user must have Kubernetes cluster configuration environment variable or the kube config file:
$ env | grep -i kube
KUBECONFIG=/etc/kubernetes/admin.conf
$ ls ~/.kube/config
config
Solution:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
echo 'export KUBECONFIG=$HOME/.kube/config' >> $HOME/.bashrc
# try your get pods command now
kubectl get pods
# further troubleshooting
## Minimum verbosity
kubectl get pods --v=0
## Debug level verbosity
kubectl get pods --v=4
## Maximum verbosity
kubectl get pods --v=9
- The containerd service must be running:
systemctl status containerd
- The kubelet service must be running:
systemctl status kubelet
- TCP port 6443 should be listed as the listening port:
netstat -pnlt | grep 6443
tcp6 0 0 :::6443 :::* LISTEN 2785/kube-apiserver
- If TCP port 6443 is not available, check kubelet logs:
journalctl -xeu kubelet
- Verify k8s certificates have not expired. If expired, then follow How to renew certificates on Kubernetes
kubeadm alpha certs check-expiration
- Open a new support ticket for further troubleshooting