k3d icon indicating copy to clipboard operation
k3d copied to clipboard

[BUG] K3d in Windows uses host.docker.internal when generating kubeconfig

Open strowk opened this issue 7 months ago • 1 comments

What did you do

  • How was the cluster created?

    • k3d cluster create mycluster --wait --timeout 5m
  • What did you do afterwards?

    • k3d kubeconfig get mycluster > kubeconfig
    • KUBECONFIG=./kubeconfig kubectl get pods -A

What did you expect to happen

List of pods shown.

Screenshots or terminal output

E0409 00:29:09.605422   14176 memcache.go:265] couldn't get current server API group list: Get "https://host.docker.internal:55757/api?timeout=32s": dial tcp 192.168.1.105:55757: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
E0409 00:29:30.632793   14176 memcache.go:265] couldn't get current server API group list: Get "https://host.docker.internal:55757/api?timeout=32s": dial tcp 192.168.1.105:55757: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
E0409 00:29:51.666673   14176 memcache.go:265] couldn't get current server API group list: Get "https://host.docker.internal:55757/api?timeout=32s": dial tcp 192.168.1.105:55757: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I looked at generated kubeconfig file and it has there host.docker.internal for server, which it really should not, since this is not intended to be used from the host. Instead this should be localhost.

The issue appears to be in this code - https://github.com/k3d-io/k3d/blob/605e6f62caecf750bc19da4c055a76e784138c1e/pkg/client/kubeconfig.go#L164-L165

It should simply use 'localhost', not something that came from the node, since those are different networks.

Which OS & Architecture

  • output of k3d runtime-info
arch: x86_64
cgroupdriver: cgroupfs
cgroupversion: "1"
endpoint: /var/run/docker.sock
filesystem: extfs
infoname: docker-desktop
name: docker
os: Docker Desktop
ostype: linux
version: 28.0.4

Which version of k3d

  • output of k3d version
k3d version v5.8.3
k3s version v1.31.5-k3s1 (default)

Which version of docker

  • output of docker version and docker info
Client:
 Version:           28.0.4
 API version:       1.48
 Go version:        go1.23.7
 Git commit:        b8034c0
 Built:             Tue Mar 25 15:07:48 2025
 OS/Arch:           windows/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.40.0 (187762)
 Engine:
  Version:          28.0.4
  API version:      1.48 (minimum version 1.24)
  Go version:       go1.23.7
  Git commit:       6430e49
  Built:            Tue Mar 25 15:07:22 2025
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.26
  GitCommit:        753481ec61c7c8955a23d6ff7bc8e4daed455734
 runc:
  Version:          1.2.5
  GitCommit:        v1.2.5-0-g59923ef
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

strowk avatar Apr 08 '25 22:04 strowk

Just a note, I think this host.docker.internal can and does sometimes work, it is just not reliable due to the simple fact that this is being set in "hosts" file, which docker cannot even modify without asking for permission, so whenever IP address of host machine changes for whatever reason, user would have to trigger docker into updating that thing (the only thing that works for me now is reinstalling it completely :( ).

I know that this is essentially the issue of how docker implementation is designed around editing this hosts file, but I believe that UX of using k3d could be improved easily if simply use "localhost" in generated kubeconfig, since nothing except localhost makes much sense to have there.

strowk avatar Apr 08 '25 22:04 strowk

so is it supposed to be localhost or host.docker.internal?

AizenSousuke avatar Sep 04 '25 13:09 AizenSousuke