简体   繁体   中英

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

I'm trying to use KIND to spin up my Kubernetes cluster and trying to use it with Kubectl but I'm stymied at the first hurdle

I set up a cluster using the following kind config

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

Then I use kubectl

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

This makes sense because if I do 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

What do I have to do to start the kubernetes API server and get the nodes on it?

I'm trying to use KIND to spin up my Kubernetes cluster and trying to use it with Kubectl but I'm stymied at the first hurdle

I set up a cluster using the following kind config

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

Then I use kubectl

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

This makes sense because if I do 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

What do I have to do to start the kubernetes API server and get the nodes on it?

Most likely problem and the one that usually gets me is that you don't have a .kube directory with the right config in it. Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM