Lundrea Lundrea's技术博客, 专注于后端与基础架构!

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

2023-08-27
Lundrea

概述

k8s集群在节点运行kubectl命令时出现错误:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
出现这个问题的原因是kubectl命令需要使用kubernetes-admin来运行

解决方法

依次进行下述步骤:

  1. 首先将主节点中的/etc/kubernetes/admin.conf文件拷贝到从节点相同的目录下
  2. 配置环境变量echo export KUBECONFIG=/etc/kubernetes/admin.conf » ~/.bash_profile(这句要手打,不要复制粘贴,尤其是»,否则会出错)
  3. 使环境变量生效source ~/.bash_profile

Comments

Content