k8s的worker node节点运行kubectl报错:The connection to the server localhost:8080 was refused

一、现象

[root@redis-01 kubernetes]# kubectl get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?
[root@redis-01 kubernetes]# 

二、原因

kubectl运行需要使用kubernetes-admin来运行

三、解决

1、将master节点的/etc/kubernetes/admin.conf复制从node节点的/etc/kubernetes目录下

[root@master69 kubernetes]# scp -P25601 admin.conf root@172.28.5.120:/etc/kubernetes/

2、配置环境变量KUBECONFIG

[root@redis-01 kubernetes]# echo "export KUBECONFIG=/etc/kubernetes/admin.conf">>/etc/profile
[root@redis-01 kubernetes]# source /etc/profile
[root@redis-01 kubernetes]# echo $KUBECONFIG
/etc/kuberbetes/admin.conf

3、执行验证

[root@redis-01 kubernetes]# kubectl get pods -n kube-system
NAME                                READY   STATUS             RESTARTS   AGE
etcd-localhost                      1/1     Running            0          46h
kube-apiserver-localhost            1/1     Running            0          11h
kube-controller-manager-localhost   1/1     Running            3          46h
kube-flannel-ds-8bx7f               1/1     Running            0          42h
kube-flannel-ds-drfqk               1/1     Running            0          41h
kube-flannel-ds-hx4tk               1/1     Running            0          41h
kube-flannel-ds-spl2l               1/1     Running            0          46h
kube-proxy-2564b                    1/1     Running            0          41m
kube-proxy-jltvv                    1/1     Running            0          41m
kube-proxy-kdv62                    1/1     Running            0          41m
kube-proxy-slgcq                    1/1     Running            1          41m
kube-scheduler-localhost            1/1     Running            3          46h
原文地址:https://www.cnblogs.com/sky-cheng/p/14239549.html