1、使用kubectl 命令是报错
报错:
[root@k8s-master ~]# kubectl get pod The connection to the server localhost:8080 was refused - did you specify the right host or port?
原因: 由于使用kubeadm安装的k8s ,所以需要使用 kubernetes-admin 来运行。
解决方法: (如果admin.conf没有就从k8s-master上copy一份到当前节点)
[root@k8s-master ~]# export KUBECONFIG=/etc/kubernetes/admin.conf [root@k8s-master ~]# kubectl get pod No resources found. [root@k8s-master ~]# kubectl get node NAME STATUS ROLES AGE VERSION k8s-master Ready master 46h v1.14.0 [root@k8s-master ~]#
#也可以编辑 ~/.bash_profile,, 如果使用的是 zsh 那就编辑 ~/.zshrc
添加内容
export KUBECONFIG=/etc/kubernetes/admin.conf
使其生效
source ~/.bash_profile 如果是zsh source ~/.zshrc
qingfeng