Kubernetes-kubectl The connection to the server localhost:8080 was refused -did you specify

今天在Kubernetes的從節點上運行命令【kubectl】出現瞭如下錯誤:

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

出現這個問題的原因是kubectl命令需要使用kubernetes-admin來運行,解決方法如下,將主節點中的【/etc/kubernetes/admin.conf】文件拷貝到從節點相同目錄下,然後如提示配置環境變量:

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

也可以簡單方法

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile

source ~/.bash_profile

接着再運行kubectl命令就OK了

[root@172-19-102-78 ~]# kubectl get cs
NAME                 STATUS    MESSAGE             ERROR
scheduler            Healthy   ok                  
controller-manager   Healthy   ok                  
etcd-0               Healthy   {"health":"true"} 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章