Kubernetes-kubectl命令出現錯誤
【The connection to the server localhost:8080 was refused - did you specify the right host or port?】
[root@docker001 yum.repos.d]# kubectl get pods --all-namespaces The connection to the server localhost:8080 was refused - did you specify the right host or port? [root@docker001 yum.repos.d]# ll /etc/kubernetes/admin.conf -rw------- 1 root root 5450 Oct 23 14:10 /etc/kubernetes/admin.conf [root@docker001 yum.repos.d]# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile [root@docker001 yum.repos.d]# source ~/.bash_profile [root@docker001 yum.repos.d]# source ~/.bash_profile [root@docker001 yum.repos.d]# kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-5644d7b6d9-8vbs4 0/1 Pending 0 5m39s kube-system coredns-5644d7b6d9-jc4zk 0/1 Pending 0 5m39s kube-system etcd-docker001 1/1 Running 0 4m47s kube-system kube-apiserver-docker001 1/1 Running 0 4m22s kube-system kube-controller-manager-docker001 1/1 Running 0 4m42s kube-system kube-proxy-bxhpn 1/1 Running 0 5m39s kube-system kube-scheduler-docker001 1/1 Running 0 4m33s [root@docker001 yum.repos.d]#
如果以上的步驟並不能解決你的問題,你可以試一下下面的這個方法,這個方法適用於關機重啟以后出現的報錯!!!
The connection to the server IP:6443 was refused - did you specify the right host or port?
在安裝配置好 Kubernetes 后,正常情況下服務器關機重啟,kubelet 也會自動啟動的。但最近配置的一台服務器重啟后,輸入命令 kubectl get nodes 查看節點報如下錯誤:
輸入 systemctl status kubelet 命令查看 kubelet 的情況,發現 kubelet 確實沒有啟動
2,問題原因
由於 K8s 必須保持全程關閉交換內存,之前我安裝是只是使用 swapoff -a 命令暫時關閉 swap。而機器重啟后,swap 還是會自動啟用,從而導致 kubelet 無法啟動。
3,解決辦法
(1)首先執行如下命令關閉 swap。
swapoff -a
(2)接着編輯 /etc/fstab 文件。
vi /etc/fstab
(3)將 /dev/mapper/centos-swap swap swap default 0 0 這一行前面加個 # 號將其注釋掉。

(4)編輯完畢后保存退出。這樣機器重啟后 kubelet 也可以正常自動啟動了。
原文出自:www.hangge.com 轉載請保留原文鏈接:https://www.hangge.com/blog/cache/detail_2419.html