abiosoft/colima · error
error updating kubeconfig: %w
Error message
error updating kubeconfig: %w
What it means
Raised at the final kubeconfig install step: 'cp <tmpkubeconfFile> <kubeconfFile>' on the host failed, i.e. moving the prepared temp kubeconfig (~/.kube/.<profile>/colima-temp) into place at $KUBECONFIG-first-entry or ~/.kube/config. The backup step (if any) already succeeded; only the final overwrite failed.
Source
Thrown at environment/container/kubernetes/kubeconfig.go:96
return err
}
// save
return host.Write(tmpkubeconfFile, []byte(kubeconfig))
})
// backup current settings and save new config
a.Add(func() error {
// backup existing file if exists
if stat, err := c.host.Stat(kubeconfFile); err == nil && !stat.IsDir() {
backup := filepath.Join(filepath.Dir(tmpkubeconfFile), fmt.Sprintf("config-bak-%d", time.Now().Unix()))
if err := c.host.Run("cp", kubeconfFile, backup); err != nil {
return fmt.Errorf("error backing up kubeconfig: %w", err)
}
}
// save new config
if err := c.host.Run("cp", tmpkubeconfFile, kubeconfFile); err != nil {
return fmt.Errorf("error updating kubeconfig: %w", err)
}
return nil
})
// set new context
conf, _ := ctx.Value(config.CtxKey()).(config.Config)
if conf.AutoActivate() {
a.Add(func() error {
out, err := c.host.RunOutput("kubectl", "config", "use-context", profile)
if err != nil {
return err
}
log.Println(out)
return nil
})
}
View on GitHub (pinned to c3a5f9184d)
Solutions
- Fix ownership/permissions of the target: 'sudo chown "$(id -u)" "$KUBECONFIG"' (or ~/.kube/config) and ensure it is writable ('chmod u+w').
- Verify the first KUBECONFIG entry is a writable location ('echo "$KUBECONFIG"'; on failure use only writable paths, colon-separated lists are split via filepath.SplitList and only the first is used).
- Clear file immutability on macOS: 'sudo chflags nouchg ~/.kube/config' if 'ls -lO' shows uchg.
- Temporarily unset KUBECONFIG to let colima write the default ~/.kube/config, then merge manually.
Example fix
# before $ ls -l ~/.kube/config -rw-r--r-- 1 root staff 1234 Jan 1 00:00 /Users/me/.kube/config # after $ sudo chown "$(id -u):$(id -g)" ~/.kube/config $ colima start --kubernetes
Defensive patterns
Strategy: validation
Validate before calling
// verify the target kubeconfig path is writable before the chain runs
if fi, err := os.Stat(kubeconfFile); err == nil {
if fi.Mode().Perm()&0222 == 0 {
return fmt.Errorf("%s is read-only; chmod u+w before continuing", kubeconfFile)
}
} Try / catch
if err := c.host.Run("cp", tmpkubeconfFile, kubeconfFile); err != nil {
if strings.Contains(err.Error(), "Permission denied") {
return fmt.Errorf("error updating kubeconfig (fix ownership of %s): %w", kubeconfFile, err)
}
return fmt.Errorf("error updating kubeconfig: %w", err)
} Prevention
- Check 'ls -l ${KUBECONFIG:-~/.kube/config}' ownership after any sudo usage.
- Avoid pointing KUBECONFIG at synced/managed folders.
- Keep ~/.kube on the native home volume, not a read-only mount.
When it happens
Trigger: Target kubeconfig path is read-only (chmod 444, or on a read-only mount); the file is root-owned from earlier sudo usage; KUBECONFIG's first entry lives in a non-writable directory; target file is immutable (chflags on macOS); antivirus/file-lock (corporate endpoint software) blocking writes; the temp file was deleted between steps.
Common situations: Ran kubectl/colima as root previously so ~/.kube/config is root-owned; KUBECONFIG points into a synced/protected folder (OneDrive, Dropbox, managed device); read-only home in hardened CI environments.
Related errors
- error backing up kubeconfig: %w
- error retrieving home directory on host
- error persisting kubernetes settings: %w
- error fetching kubeconfig on guest: %w
- error persisting runtime settings: %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/0de76daeebf0d413.
Report an issue: GitHub.