Skip to content

hack: repoint the kind kubeconfig when it cannot reach the apiserver - #1292

Open
Yuan Gao (ygao-g) wants to merge 3 commits into
agent-substrate:mainfrom
ygao-g:kind-kubeconfig-verify
Open

hack: repoint the kind kubeconfig when it cannot reach the apiserver#1292
Yuan Gao (ygao-g) wants to merge 3 commits into
agent-substrate:mainfrom
ygao-g:kind-kubeconfig-verify

Conversation

@ygao-g

Copy link
Copy Markdown
Collaborator

Fixes #1099

Stacked on #958 — merge that first. The first two commits here are #958's; only
the last one is new. #958 removes the unconditional repoint; this restores it in
a checked form, which is what #1099 tracks.

Where the Docker daemon lives in a VM (Lima on macOS, for instance), kind
publishes the port inside the VM at [::1] and limactl re-forwards it to the
host's v4 loopback only, so an IPv6-only cluster is left with an unreachable
[::1] kubeconfig entry and the next kubectl dies at connect. See
lima-vm/lima#1540.

The script now probes that entry once and, if it is refused, repoints at
https://localhost:<port>. localhost is the only spelling that reaches it:
[::1] is refused because limactl does not forward v6, and 127.0.0.1 connects
but fails verification, because the cert an IPv6-only cluster issues carries
localhost as a DNS SAN and no v4 IP SAN. One probe is enough because #958's
in-node wait has already established readiness: a refusal here means the address
is wrong, not that the apiserver is slow, so there is no retry to mask a real
outage. #877 rewrote the entry unconditionally, which is what broke hosts where
localhost is v4-only. The probe runs for every IP_FAMILY: on ipv4 and dual it
answers first try and nothing is rewritten.

Verified by hand. CI cannot cover this — a GitHub runner reaches its own
published port, so the new code is a no-op there.

host, IP_FAMILY=ipv6 on #958 with this PR
inside the Linux guest comes up clean, kubeconfig https://[::1]:41985 unchanged — probe answers, nothing rewritten
macOS client, daemon in a Lima VM dial tcp [::1]:49276: connect: connection refused at the CoreDNS patch, exit 1 [::1]:52600 refused, repointed to https://localhost:52600, exit 0

The first row is the regression guard for the behaviour #958 fixes; the second is
the case it leaves broken. An IP_FAMILY=ipv4 run on the same host is a no-op:
nothing is rewritten and the kubeconfig is left at https://127.0.0.1:<port>.

  • Tests pass (shellcheck, plus IP_FAMILY=ipv6 and IP_FAMILY=ipv4 runs on a macOS/Lima host)
  • Appropriate changes to documentation are included in the PR

🤖 Generated with Claude Code

On an IPv6-only cluster the script rewrote kind's `https://[::1]:PORT`
kubeconfig entry to `https://localhost:PORT` unconditionally. That
breaks any host whose `/etc/hosts` leaves `localhost` off the `::1`
line, including the Ubuntu cloud image Lima runs: `localhost` resolves
v4-only and every later kubectl fails at connect. The rewrite existed
for one case, a macOS client reaching kind inside a Lima VM, where
limactl re-forwards the published port to the host's v4 loopback only.
Running the loop inside the guest reaches `[::1]` directly and avoids
that path entirely.
On a fresh IPv6-only kind cluster nothing resolves from inside a pod, so
the install never completes. CoreDNS inherits the node's IPv4 resolver,
which a v6-only pod cannot reach, and the in-cluster registry has no name
a pod can look up. This gives the cluster its own Corefile, gated on
ipv6: a forward to an IPv6 upstream, overridable with IPV6_DNS_UPSTREAM,
and a kind-registry:53 server block so atelet can pull from its own
network namespace.

The Corefile patch runs kubectl straight after `kind create`, which
returns before the apiserver answers, so the script now waits for the
control plane from inside the node first.
For macOS + Lima setup, where the daemon lives in a VM, kind publishes
the port inside the VM and limactl re-forwards it to the host's v4
loopback only, so an IPv6-only cluster leaves an unreachable [::1]
entry and the next kubectl dies at connect. The fix is to probe that
entry once and, when it is refused, repoint at whichever loopback
spelling answers.
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.

hack: the ipv6 kubeconfig repoint breaks kubectl on a native-Linux Docker host

1 participant