It seems I must run sudo swapoff -a command everytime I want to run kubectl commands because if I don't do that it gives me such a following error:

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

Is there a way to do that permanently and getting ride of always running sudo swapoff -a command?

  • Do you have enabled the swap to the kubernetes Master nodes and worker nodes? If I remember correctly, one of k8s installation requirements is to disable the swap to the nodes.
    – igiannak
    Dec 14, 2022 at 11:39

2 Answers 2


In order to disable the swap to a Linux machine, you have to elevate with root and edit /etc/fstab.
From there, remove the swap entry by commenting it out.
Upon reboot, swap will not mount.

  • I have done this before but still my Kubernetes doesn't work. Dec 14, 2022 at 21:52
  • ok. can you post your cat /etc/fstab and df outputs before do swapoff -a ?
    – igiannak
    Dec 15, 2022 at 8:37

This error is not only related to the swapfile.

It comes also as soon you join an additional node and you dont have a network fabric installed.

Like flannel https://github.com/flannel-io/flannel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.