k8s worker 节点使用kubectl 命令
通常,kubectl 命令在master节点使用,但为了方便,想要在worker节点使用该命令,如何操作?具体实现如下:
$ kubectl get pod
The connection to the server localhost:8080 was refused - did you specify the right host or port?
# worker节点无法使用
拷贝master节点文件
scp /etc/kubernetes/admin.conf root@worker-ip:/etc/kubernetes/
添加至环境变量
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile
测试
kubectl get node
NAME STATUS ROLES AGE VERSION
worker01 Ready worker 329d v1.21.0
worker02 Ready worker 379d v1.21.0
master Ready control-plane,master 389d v1.21.0
参考文档
1、https://blog.csdn.net/2301_78648680/article/details/138605057