You must be logged in to the server (unauthorized)

Problem description
K8S cluster has 3 masters with the same certificate file, one master is normal, and the other two masters have questions: enter kubectl get nodes kubectl get Po – all-minus namespaces is logged with an error You must be logged in to the server(unauthorized)
The solution
Cluster if installed using administrator:

export KUBECONFIG=/etc/kubernetes/admin.conf

If the cluster is installed with a regular user:

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

Read More: