Skip to content

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

Open
@strowk

Description

@strowk

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 -

// update the server URL
kc.Clusters["default"].Server = fmt.Sprintf("https://%s:%s", APIHost, APIPort)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions