derailed/k9s · error

no connection to dial

Error message

no connection to dial

What it means

Returned by APIClient.Dial (internal/client/client.go:464) when the connOK flag is false. Dial is the primary lazy constructor for the shared kubernetes.Interface clientset: it returns the cached client if present, otherwise builds one from RestConfig(). The connOK gate is the single health latch shared by CanI, DialLogs, Dial and CachedDiscovery, flipped off by any failed connectivity probe.

Source

Thrown at internal/client/client.go:464

	cfg, err := a.RestConfig()
	if err != nil {
		return nil, err
	}
	cfg.Timeout = 0
	c, err := kubernetes.NewForConfig(cfg)
	if err != nil {
		return nil, err
	}
	a.setLogClient(c)

	return a.getLogClient(), nil
}

// Dial returns a handle to api server or die.
func (a *APIClient) Dial() (kubernetes.Interface, error) {
	if !a.getConnOK() {
		return nil, errors.New("no connection to dial")
	}
	if c := a.getClient(); c != nil {
		return c, nil
	}

	cfg, err := a.RestConfig()
	if err != nil {
		return nil, err
	}
	c, err := kubernetes.NewForConfig(cfg)
	if err != nil {
		return nil, err
	}
	a.setClient(c)

	return a.getClient(), nil
}

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. Verify and restore connectivity first: kubectl get --raw /readyz, then CheckConnectivity() until true
  2. Recreate/re-init the APIClient (its caches and clients were reset when the connection dropped)
  3. Correct the kubeconfig (server, certificate-authority, exec credentials) if RESTConfig() itself errors
  4. Treat repeated failures as a fatal session error rather than looping

Example fix

// before
c, err := apiClient.Dial()

// after
if !apiClient.CheckConnectivity() {
    return nil, fmt.Errorf("cannot dial: api server connection is down")
}
c, err := apiClient.Dial()
Defensive patterns

Strategy: validation

Validate before calling

if apiClient.CheckConnectivity() {
    c, err := apiClient.Dial()
    // use c
}

Try / catch

c, err := apiClient.Dial()
if err != nil {
    if strings.Contains(err.Error(), "no connection to dial") {
        // precondition: reconnect or surface fatal 'cluster unreachable' to user
    }
    return err
}

Prevention

When it happens

Trigger: Calling Dial() after CheckConnectivity() failed (RESTConfig error, kubernetes.NewForConfig error, or ServerVersion() error), or on a freshly created client that never connected.

Common situations: Working offline or on a flaky link; kubeconfig context pointing to a decommissioned cluster; the API server restarting during a session; automated tests that build an APIClient without a live cluster.

Related errors


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/efa234411819eed0. Report an issue: GitHub.