[ERROR IsPrivilegedUser]: user is not running as root
When setting up a Kubernetes cluster with kubeadm, you may encounter an error when trying to join a worker node to the cluster.
The specific error message you'll see is:
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR IsPrivilegedUser]: user is not running as root
[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
This error is due to non root command execiton.
Error Explanation
This error occurs because the command is being executed by a non-root user. kubeadm requires certain commands to be run with root privileges to perform necessary setup tasks.
Solution
To resolve this issue, you need to ensure that the kubeadm join command is executed with root privileges.
You have two options to achieve this:
Run the Command as the Root User:Switch to the root user and then execute the kubeadm join command. You can do this by running:
sudo -i
kubeadm join 192.168.201.10:6443 --token cyvaxk.zuc4v8s1cya8valz --discovery-token-ca-cert-hash sha256:857cda3cbcb5b6f3c91c5a059eba78242183281bafa220d19306167a08376450
Use sudo
to Execute the Command: Alternatively, you can prepend sudo
to the kubeadm join command:
sudo kubeadm join 192.168.201.10:6443 --token cyvaxk.zuc4v8s1cya8valz --discovery-token-ca-cert-hash sha256:857cda3cbcb5b6f3c91c5a059eba78242183281bafa220d19306167a08376450