master节点可以正常使用kubectl
#默认node2节点无法使用kubectl管理
#node节点
[root@k8s-node2 ~]# mkdir ~/.kube
#master节点
[root@k8s-master ~]# cp /etc/kubernetes/admin.conf /home/student/.kube/
[root@k8s-master ~]# cp /etc/kubernetes/pki/ca.crt /home/student/.kube/
[root@k8s-master ~]# scp ~/.kube/* k8s-node2:~/.kube/
#node2节点操作
[root@k8s-node2 ~]# echo export KUBECONFIG=$HOME/.kube/admin.conf >> ~/.bash_profile
[root@k8s-node2 ~]# echo 'source <(kubeadm completion bash)' >> ~/.bash_profile
[root@k8s-node2 ~]# echo 'source <(kubectl completion bash)' >> ~/.bash_profile
[root@k8s-node2 ~]# source ~/.bash_profile
[root@k8s-node2 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 38d v1.21.0
k8s-node1 Ready <none> 38d v1.21.0
k8s-node2 Ready <none> 38d v1.21.0