k8s的worker node節點運行kubectl報錯:The connection to the server localhost:8080 was refused - did you specify the right host or port?


一、現象

[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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM