运行kubectl get pods
使用sudo:为什么kubectl与sudo有不同的行为?
sudo kubectl get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?
运行作为一个普通用户:
kubectl get pods
No resources found.
运行kubectl get pods
使用sudo:为什么kubectl与sudo有不同的行为?
sudo kubectl get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?
运行作为一个普通用户:
kubectl get pods
No resources found.
默认情况下,kubectl看起来在〜/ .kube /配置(或指向的文件是$ KUBECONFIG)至确定要连接的服务器。以root身份运行命令时,您的主目录和环境是不同的。当没有连接信息时发现,kubectl缺省为localhost:8080
你会从普通用户运行这些命令:
sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
这将在你的普通用户的主目录已复制配置文件,这是为什么你能够从正常的主机而不是从sudo获得连接。
像这样运行'kubectl --kubeconfig =/home/admin/.kube/config' – sfgroups