1. 程式人生 > 其它 >解決The connection to the server localhost:8080 was refused - did you specify the right host or port?

解決The connection to the server localhost:8080 was refused - did you specify the right host or port?

技術標籤:k8skubernetes

1.問題

在這裡插入圖片描述

2.原因

kubectl命令需要使用kubernetes-admin來執行,需要admin.conf檔案(conf檔案是通過“ kubeadmin init”命令在主節點/etc/kubernetes 中建立),但是從節點沒有conf檔案,也沒有設定 KUBECONFIG =/root/admin.conf環境變數,所以需要複製conf檔案到從節點,並設定環境變數就OK了

3.資料

https://github.com/kubernetes/kubernetes/issues/50295
https://discuss.kubernetes.io/t/the-connection-to-the-server-localhost-8080-was-refused-did-you-specify-the-right-host-or-port/1464

4.解決

主節點的admin.conf拷貝到從節點,設定環境變數

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

#拷貝admin.conf注意路徑
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile