KIND和kubectl:与服务器localhost:8080的连接被拒绝-您是否指定了正确的主机或端口?

问题描述

我试图使用KIND来启动我的Kubernetes集群,并尝试将其与Kubectl一起使用,但是我遇到了第一个障碍

我使用以下种类的配置来设置集群

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
    - hostPort: 80
      containerPort: 80

然后我用kubectl

kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?

这很有意义,因为如果我这样做docker ps

CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                       NAMES
9dcd3b6fd19d        kindest/node:v1.17.11   "/usr/local/bin/entr…"   14 minutes ago      Up 14 minutes       127.0.0.1:44609->6443/tcp   kind-control-plane

启动Kubernetes API服务器并在其上获取节点,我该怎么做?

解决方法

我用 sudo chmod 0644 /etc/kubernetes/admin.confexport KUBECONFIG=/etc/kubernetes/admin.conf

解决了这个问题