ctlptl icon indicating copy to clipboard operation
ctlptl copied to clipboard

k3d on mac "timed out waiting for cluster to start" | wrong hostname to connect to cluster

Open jwmay2012 opened this issue 3 years ago • 2 comments

Waiting 5m for Kubernetes cluster "k3d-k3s-default" to start...
timed out waiting for cluster to start: Get "https://host.docker.internal:49730/version": context deadline exceeded

When trying to start a k3d cluster on mac, ctlptl fails to detect cluster is online because it's using the docker internal name for the host machine (host.docker.internal), not the machine hostname outside of docker (localhost).

Steps to Reproduce

Install k3d and ctlptl

# https://k3d.io/v5.4.3/#installation
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
brew install tilt-dev/tap/ctlptl

ctlptl-k3d.yml

apiVersion: ctlptl.dev/v1alpha1
kind: Cluster
product: k3d
registry: ctlptl-k3d-registry
---
apiVersion: ctlptl.dev/v1alpha1
kind: Registry
name: ctlptl-k3d-registry
port: 5000

apply cluster config

ctlptl apply -f ctlptl-k3d.yml

after 5 minute timeout we get an error

...
INFO[0016] Cluster 'k3s-default' created successfully!  
INFO[0016] You can now use it like this:                
kubectl cluster-info
Switched to context "k3d-k3s-default".
Waiting 5m for Kubernetes cluster "k3d-k3s-default" to start...
timed out waiting for cluster to start: Get "https://host.docker.internal:49730/version": context deadline exceeded

However, the k8s controller is available at https://localhost:49730/version

Temporary FIx

add host.docker.internal to /etc/hosts

sudo echo "127.0.0.1  host.docker.internal" | sudo tee -a  /etc/hosts

apply command now works fully

...
INFO[0016] Cluster 'k3s-default' created successfully!  
INFO[0016] You can now use it like this:                
kubectl cluster-info
Switched to context "k3d-k3s-default".
cluster.ctlptl.dev/k3d-k3s-default created

jwmay2012 avatar Jun 28 '22 17:06 jwmay2012

are you able to create a cluster successfully with k3d outside of ctlptl? e.g., run k3d cluster create and kubectl cluster-info?

ctlptl uses the connection settings that k3d tells it to. The problems you're having sound a lot like this k3d bug: https://github.com/k3d-io/k3d/issues/1057

nicks avatar Jun 28 '22 17:06 nicks

I think you're right. For some reason k3d is picking host.docker.internal as a resolvable hostname for the cluster. To get the cluster to create successfully I have to do k3d cluster create --api-port localhost:6443, or add host.docker.internal to my /etc/hosts.

My issue seems subtly different. I think their issue is that their machine is resolving host.docker.internal from the os level even with ping, but for me i get ping: cannot resolve host.docker.internal: Unknown host, which should be correct.

Is there a way to pass this --api-port option to ctlptl? I see https://github.com/tilt-dev/ctlptl/issues/224, so maybe not currently.

I guess for now, my solution is to keep the /etc/hosts fix.

sudo echo "127.0.0.1  host.docker.internal" | sudo tee -a  /etc/hosts

jwmay2012 avatar Jun 28 '22 18:06 jwmay2012