Search code examples
kuberneteskubectl

For what reasons kubectl get pods fail


Iam plunging into kubernetes to check it's status I run kubectl get pods command then iam getting error

For what reasons kubect get pods fail?

Getting error :The connection to the server xxxxxxxxx:6443 was refused-did you specify the right host or port?

How to fix this error?


Solution

  • The connection to the server xxxxxxxxx:6443 was refused-did you specify the right host or port?

    As explained in this doc by Greek Diary ‘admin’ which clears up how to fix the kubectl error

    Below troubleshooting steps will assist you to resolve your issue:

    1.The kubectl should be executed on the Master Node.

    2.Current user must have Kubernetes cluster configuration environment variable (Details of how to are listed under section Preparing to Use Kubernetes as a Regular User),

    $ env \| grep -i kube
    
    
    
    KUBECONFIG=/root/.kube/config
    

    3.The docker service must be running:

    $ systemctl status docker
    

    4.The kubelet service must be running:

    $ systemctl status kubelet
    

    5.TCP port 6443 should be listed as it is listening to port:

    netstat -pnlt \| grep 6443
    

    If TCP port 6443 is not available, check firewall/iptables rules matching requirements: $ firewall-cmd --list-all

    Also check kubelet logs:

    # journalctl -xeu kubelet
    

    6.Try restarting Kubernetes cluster which will also do some basic checks:

    $ [kubeadm-setup.sh](http://kubeadm-setup.sh) restart
    

    For what reasons do kubectl pods fail?

    Refer to this doc by Ross Kukulinski for more information about kubectl get pods fails