<p>I am diving into K8s and deployed my first pod via <code>kubectl apply</code> on the master node. In order to check its status, I called <code>kubectl get pods</code> twice in a row. I did not touch anything, but a subsequent call of the same command failed with the error below. Can anyone help me understand what may have happened?</p>
<pre><code>ubuntu:~$ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE
nginx   0/1     Pending   0          18s
ubuntu:~$ kubectl get pods
The connection to the server xxx.xxx.xxx.xxx:6443 was refused - did you specify the right host or port?
</code></pre>
<p>For completion, here the status of <code>kubelet.service</code> on the master node:</p>
<pre><code>● kubelet.service - kubelet: The Kubernetes Node Agent
     Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/kubelet.service.d
             └─10-kubeadm.conf
     Active: active (running) since Thu 2023-04-20 02:12:52 UTC; 23min ago
</code></pre>
<p>Thanks for any hint.</p>

Daniel Stephens
<p>As explained in this <a href="https://www.thegeekdiary.com/troubleshooting-kubectl-error-the-connection-to-the-server-x-x-x-x6443-was-refused-did-you-specify-the-right-host-or-port/" rel="nofollow noreferrer">doc</a> by Greek Diary ‘admin’ which explains how to fix the kubectl error:<code>The connection to the server x.x.x.x:6443 was refused - did you specify the right host or port?</code></p>
<p><strong>Below troubleshooting steps will help to resolve your issue</strong>:</p>
<blockquote>
<ol>
<li><p>The kubectl should be executed on the Master Node.</p>
</li>
<li><p>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),</p>
<p><code>$ env | grep -i kube</code></p>
<p><code>KUBECONFIG=/root/.kube/config</code></p>
</li>
</ol>
<p>3.The docker service must be running:</p>
<pre><code> $ systemctl status docker
</code></pre>
<p>4.The kubelet service must be running:</p>
<pre><code>   $ systemctl status kubelet
</code></pre>
<p>5.TCP port 6443 should be listed as it is listening to port:</p>
<pre><code>netstat -pnlt | grep 6443
</code></pre>
<p>If TCP port 6443 is not available, check firewall/iptables rules
matching requirements:</p>
<pre><code>$ firewall-cmd --list-all
</code></pre>
<p>Also check kubelet logs:</p>
<pre><code># journalctl -xeu kubelet
</code></pre>
<p>6.Try restarting Kubernetes cluster which will also do some basic checks:</p>
<pre><code>   $ kubeadm-setup.sh restart
</code></pre>
</blockquote>
