Skip to content

Conversation

Copy link

Copilot AI commented Dec 1, 2025

What

Changes the DefaultAPIHost constant from 0.0.0.0 to 127.0.0.1 in pkg/types/defaults.go, and adds backward compatibility checks for explicit 0.0.0.0 values in places where special handling is needed.

// In pkg/types/defaults.go
const DefaultAPIHost = "127.0.0.1"

Why

0.0.0.0 is a valid bind address for servers but not a valid connect address for clients. Tools like Headlamp fail to connect when kubeconfig contains https://0.0.0.0:PORT.

Fixes #1503

Implications

  • CLI behavior: Kubeconfig will now use 127.0.0.1 instead of 0.0.0.0 when no explicit host is specified
  • Existing clusters: No impact on running clusters; only affects newly generated kubeconfig
  • Explicit overrides: Users specifying --api-port HOST:PORT will still get their specified host
  • Backward compatibility: Added checks for both DefaultAPIHost and "0.0.0.0" in pkg/client/registry.go and pkg/client/cluster.go to handle cases where users explicitly provide 0.0.0.0
  • Non-breaking: Change only affects the kubeconfig output, not the actual port binding behavior
Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] context saved in kubectl config set as 0.0.0.0</issue_title>
<issue_description>## What did you do

  • How was the cluster created?
    k3d registry create linkerd --default-network podman
    k3d cluster create linkerd --registry-use k3d-linkerd -a 2 -s 1 -i rancher/k3s:v1.32.0-k3s1

  • What did you do afterwards?
    kubectl works fine but tools like headlamp won't connect i solved this by changing https://0.0.0.0:11892 https://127.0.0.1:11892

What did you expect to happen

headlamp should connect to the cluster

Screenshots or terminal output

If applicable, add screenshots or terminal output (code block) to help explain your problem.

Which OS & Architecture

i'm running this on windows 11 with podman desktop 1.15 & wsl 2 installed

lient:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.23.3
Git Commit:   4cbdfde5d862dcdbe450c0f1d76ad75360f67a3c
Built:        Fri Nov 22 02:45:23 2024
OS/Arch:      windows/amd64

Server:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.22.7
Built:        Thu Nov 21 11:00:00 2024
OS/Arch:      linux/amd64

Which version of k3d

k3d version v5.7.5
k3s version v1.30.6-k3s1 (default)

Which version of docker

podman version 

arch: amd64
cgroupdriver: cgroupfs
cgroupversion: "1"
endpoint: /var/run/docker.sock
filesystem: extfs
infoname: adampc
name: docker
os: fedora
ostype: linux
version: 5.3.1
PS C:\Users\adam.ADAMCIRILLO> podman version
Client:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.23.3
Git Commit:   4cbdfde5d862dcdbe450c0f1d76ad75360f67a3c
Built:        Fri Nov 22 02:45:23 2024
OS/Arch:      windows/amd64

Server:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.22.7
Built:        Thu Nov 21 11:00:00 2024
OS/Arch:      linux/amd64
PS C:\Users\adam.ADAMCIRILLO> podman version
Client:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.23.3
Git Commit:   4cbdfde5d862dcdbe450c0f1d76ad75360f67a3c
Built:        Fri Nov 22 02:45:23 2024
OS/Arch:      windows/amd64

Server:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.22.7
Built:        Thu Nov 21 11:00:00 2024
OS/Arch:      linux/amd64

podman info

host:
  arch: amd64
  buildahVersion: 1.38.0
  cgroupControllers:
  - cpuset
  - cpu
  - cpuacct
  - blkio
  - memory
  - devices
  - freezer
  - net_cls
  - perf_event
  - net_prio
  - hugetlb
  - pids
  - rdma
  - misc
  cgroupManager: cgroupfs
  cgroupVersion: v1
  conmon:
    package: conmon-2.1.12-2.fc40.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.12, commit: '
  cpuUtilization:
    idlePercent: 97.73
    systemPercent: 0.92
    userPercent: 1.35
  cpus: 8
  databaseBackend: sqlite
  distribution:
    distribution: fedora
    variant: container
    version: "40"
  eventLogger: journald
  freeLocks: 2025
  hostname: adampc
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 5.15.167.4-microsoft-standard-WSL2
  linkmode: dynamic
  logDriver: journald
  memFree: 28950421504
  memTotal: 33634131968
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    dns:
      package: aardvark-dns-1.13.1-1.fc40.x86_64
      path: /usr/libexec/podman/aardvark-dns
      version: aardvark-dns 1.13.1
    package: netavark-1.13.1-1.fc40.x86_64
    path: /usr/libexec/podman/netavark
    version: netavark 1.13.1
  ociRuntime:
    name: crun
    package: crun-1.19.1-1.fc40.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.19.1
      commit: 3e32a70c93f5aa5fea69b50256cca7fd4aa23c80
      rundir: /run/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJL
  os: linux
  pasta:
    executable: /usr/bin/pasta
    package: passt-0^20241211.g09478d5-1.fc40.x86_64
    version: |
      pasta 0^20241211.g09478d5-1.fc40.x86_64
      Copyright Red Hat
      GNU General Public License, version 2 or later
        <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
  remoteSocket:
    exists: true
    path: unix:///run/podman/podman.sock
  rootlessNetworkCmd: pasta
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: false
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: false
  serviceIsRemote: true
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree...

</details>

- Fixes k3d-io/k3d#1543

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

When generating the kubeconfig, if the API host is 0.0.0.0 (the default),
replace it with 127.0.0.1 since 0.0.0.0 means "bind to all interfaces"
but is not a valid address for clients to connect to.

This fixes issues with tools like Headlamp that cannot connect to the
cluster when the server URL uses 0.0.0.0.

Fixes #1503

Co-authored-by: iwilltry42 <25345277+iwilltry42@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix context saved in kubectl config as 0.0.0.0 Fix: Replace 0.0.0.0 with 127.0.0.1 in kubeconfig server URL Dec 1, 2025
Copilot AI requested a review from iwilltry42 December 1, 2025 13:13
Copilot finished work on behalf of iwilltry42 December 1, 2025 13:13
Copy link
Member

@iwilltry42 iwilltry42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should change the DefaultAPIHost constant instead and potentially add checks for both the value from the constant and 0.0.0.0 in some places

Per reviewer feedback, changed the DefaultAPIHost constant from 0.0.0.0
to 127.0.0.1 instead of adding a runtime check. Also added checks for
both the constant value and "0.0.0.0" in places where users might
explicitly provide 0.0.0.0 for backward compatibility.

Changes:
- pkg/types/defaults.go: Changed DefaultAPIHost to 127.0.0.1
- pkg/client/registry.go: Added check for both DefaultAPIHost and 0.0.0.0
- pkg/client/cluster.go: Added check for both DefaultAPIHost and 0.0.0.0
- pkg/client/kubeconfig.go: Removed runtime replacement logic
- pkg/client/kubeconfig_test.go: Updated test to verify constant value

Co-authored-by: iwilltry42 <25345277+iwilltry42@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 1, 2025

You should change the DefaultAPIHost constant instead and potentially add checks for both the value from the constant and 0.0.0.0 in some places

Changed DefaultAPIHost from 0.0.0.0 to 127.0.0.1 and added checks for both values in pkg/client/registry.go and pkg/client/cluster.go for backward compatibility when users explicitly provide 0.0.0.0. Commit: 1ba9ac3

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • update.k3s.io
    • Triggering command: /usr/bin/curl curl --silent --retry 3 REDACTED (dns block)
    • Triggering command: /usr/bin/curl curl REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix: Replace 0.0.0.0 with 127.0.0.1 in kubeconfig server URL Fix: Change DefaultAPIHost from 0.0.0.0 to 127.0.0.1 Dec 1, 2025
Copilot AI requested a review from iwilltry42 December 1, 2025 13:37
Copilot finished work on behalf of iwilltry42 December 1, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants