kubernetes 到服务器localhost:8080的连接被拒绝-您指定了正确的主机或端口吗?FAQ

n53p2ov0  于 2023-03-01  发布在  Kubernetes
关注(0)|答案(6)|浏览(328)

我是kubernetes的新手。我在与集群kubectl get nodes交互时收到以下错误。
错误:The connection to the server localhost:8080 was refused - did you specify the right host or port?

blmhpbnm

blmhpbnm1#

在网上搜索之后,我解决了我的问题。

#sudo cp /etc/kubernetes/admin.conf $HOME/

#sudo chown $(id -u):$(id -g) $HOME/admin.conf
#export KUBECONFIG=$HOME/admin.conf

b1zrtrql

b1zrtrql2#

您的kubectl可能没有引用正确的kubeconfig文件,或者kubeconfig文件没有正确的详细信息。

cygmwpex

cygmwpex3#

当**kubeadm init明确指示以普通用户身份执行以下命令时,如果您错过运行这些命令,则会报告问题**。

To make kubectl work for your non-root user, run these commands, which are also part of the kubeadm init output:

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

您应在kubeadm init时间检查日志,您将发现类似于下面的内容,要求执行命令。

[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

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

You should now deploy a Pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  /docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
0sgqnhkj

0sgqnhkj4#

也许你没有设置环境变量,试试这个:

export KUBERNETES_MASTER=http://MasterIP:8080

MasterIP是您的Kubernetes主IP

rggaifut

rggaifut5#

kubectl命令中的use-context有问题。请在kubeconfig文件中进行检查。

ve7v8dk2

ve7v8dk26#

Kubeadm初始化cidr-忽略飞行前=全部
在那之后你会得到代币。
如果您仍然没有获得令牌,请将aws ec2示例配置从t2.medium升级到t2.large或t2.xlarge
之后,你会得到它的节点连接,不要忘记关联弹性IP

相关问题