<p>I follow <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/" rel="nofollow noreferrer">this</a> to install kubernetes on my cloud. 
When I run command <code>kubectl get nodes</code> I get this error: </p>

<pre><code>The connection to the server localhost:6443 was refused - did you specify the right host or port? 
</code></pre>

<p>How can I fix this?</p>

Akashii
<p>If you followed only mentioned docs it means that you have only installed <code>kubeadm</code>, <code>kubectl</code> and <code>kubelet</code>.</p>

<p>If you want to run <code>kubeadm</code> properly you need to do 3 steps more.</p>

<p><strong>1. Install docker</strong> </p>

<p>Install <a href="https://docs.docker.com/install/linux/docker-ce/ubuntu/" rel="nofollow noreferrer">Docker ubuntu version</a>. If you are using another system chose it from left menu side.</p>

<p><strong>Why:</strong></p>

<p>If you will not install docker you will receive errror like below:</p>

<pre><code>preflight] WARNING: Couldn't create the interface used for talking to the container runtime: docker is required for container runtime: exec: "docker": e
xecutable file not found in $PATH
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
        [ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
</code></pre>

<p><strong>2. Initialization of <code>kubeadm</code></strong></p>

<p>You have installed properly <code>kubeadm</code> and <code>docker</code> but now you need to initialize <code>kubeadm</code>. Docs can be found <a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/" rel="nofollow noreferrer">here</a></p>

<p>In short version you have to run command</p>

<p><code>$ sudo kubeadm init</code> </p>

<p>After initialization you will receive information to run commands like:</p>

<pre><code>mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
</code></pre>

<p>and token to join another VM to cluster. It looks like</p>

<pre><code>kubeadm join 10.166.XX.XXX:6443 --token XXXX.XXXXXXXXXXXX \
    --discovery-token-ca-cert-hash sha256:aXXXXXXXXXXXXXXXXXXXXXXXX166b0b446986dd05c1334626aa82355e7 
</code></pre>

<p>If you want to run some special action in init phase please check <a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init-phase/" rel="nofollow noreferrer">this docs</a>.</p>

<p><strong>3. Change node status to <code>Ready</code></strong></p>

<p>After previous step you will be able to execute</p>

<pre><code>$ kubectl get nodes
NAME           STATUS     ROLES    AGE     VERSION
ubuntu-kubeadm   NotReady   master   4m29s   v1.16.2
</code></pre>

<p>But your node will be in <code>NotReady</code> status. If you will describe it <code>$ kubectl describe node</code> you will see error:</p>

<pre><code>Ready            False   Wed, 30 Oct 2019 09:55:09 +0000   Wed, 30 Oct 2019 09:50:03 +0000   KubeletNotReady              runtime network not ready: Ne
tworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
</code></pre>

<p>It means that you have to install one of CNIs. List of them can be found <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#pod-network" rel="nofollow noreferrer">here</a>.</p>

<p><strong>EDIT</strong></p>

<p>Also one thing comes to my mind.</p>

<p>Sometimes when you turned off and on VM you need to restart 
kubelet and docker service. You can do it by using</p>

<pre><code>$ service docker restart
$ systemctl restart kubelet
</code></pre>

<p>Hope it helps.</p>
