kubernetes/kubernetes · error

error while loading kubeconfig from file %v: %v

Error message

error while loading kubeconfig from file %v: %v

What it means

Returned by hollowNodeConfig.createClientConfigFromFile (hollow_node.go:120) when clientcmd.LoadFromFile cannot read or parse the kubeconfig at the --kubeconfig path (default /kubeconfig/kubeconfig). kubemark needs a valid kubeconfig to build a client to the API server; any read or parse failure from LoadFromFile is wrapped here. The inner error from client-go tells you whether it was a missing file, bad perms, or malformed YAML.

Source

Thrown at cmd/kubemark/app/hollow_node.go:120

	fs.Var(&bindableNodeLabels, "node-labels", "Additional node labels")
	fs.Var(utilflag.RegisterWithTaintsVar{Value: &c.RegisterWithTaints}, "register-with-taints", "Register the node with the given list of taints (comma separated \"<key>=<value>:<effect>\"). No-op if register-node is false.")
	fs.IntVar(&c.MaxPods, "max-pods", maxPods, "Number of pods that can run on this Kubelet.")
	bindableExtendedResources := cliflag.ConfigurationMap(c.ExtendedResources)
	fs.Var(&bindableExtendedResources, "extended-resources", "Register the node with extended resources (comma separated \"<name>=<quantity>\")")
	fs.BoolVar(&c.UseHostImageService, "use-host-image-service", true, "Set to true if the hollow-kubelet should use the host image service. If set to false the fake image service will be used")

	fs.BoolVar(&c.UseRealProxier, "use-real-proxier", true, "Has no effect.")
	_ = fs.MarkDeprecated("use-real-proxier", "This flag is deprecated and will be removed in a future release.")
	fs.DurationVar(&c.ProxierSyncPeriod, "proxier-sync-period", 30*time.Second, "Has no effect.")
	_ = fs.MarkDeprecated("proxier-sync-period", "This flag is deprecated and will be removed in a future release.")
	fs.DurationVar(&c.ProxierMinSyncPeriod, "proxier-min-sync-period", 0, "Has no effect.")
	_ = fs.MarkDeprecated("proxier-min-sync-period", "This flag is deprecated and will be removed in a future release.")
}

func (c *hollowNodeConfig) createClientConfigFromFile() (*restclient.Config, error) {
	clientConfig, err := clientcmd.LoadFromFile(c.KubeconfigPath)
	if err != nil {
		return nil, fmt.Errorf("error while loading kubeconfig from file %v: %v", c.KubeconfigPath, err)
	}
	config, err := clientcmd.NewDefaultClientConfig(*clientConfig, &clientcmd.ConfigOverrides{}).ClientConfig()
	if err != nil {
		return nil, fmt.Errorf("error while creating kubeconfig: %v", err)
	}
	config.ContentType = c.ContentType
	config.QPS = c.QPS
	config.Burst = c.Burst
	return config, nil
}

func (c *hollowNodeConfig) bootstrapClientConfig() error {
	if c.BootstrapKubeconfigPath != "" {
		return bootstrap.LoadClientCert(context.TODO(), c.KubeconfigPath, c.BootstrapKubeconfigPath, c.CertDirectory, types.NodeName(c.NodeName))
	}
	return nil
}

View on GitHub (pinned to b882c60b40)

Solutions

  1. Confirm the file exists and is readable by the kubemark UID: `ls -l <kubeconfig>`.
  2. Validate it parses as kubeconfig: `kubectl config view --kubeconfig <path>` must print clusters/contexts/users.
  3. Fix the mount/flag so --kubeconfig points at the real file (default expected at /kubeconfig/kubeconfig).
  4. Regenerate the kubeconfig from the API server if it is empty or corrupt.

Example fix

// before
clientConfig, err := clientcmd.LoadFromFile(c.KubeconfigPath)
if err != nil {
    return nil, fmt.Errorf("error while loading kubeconfig from file %v: %v", c.KubeconfigPath, err)
}

// after - fail with an actionable message when the path is bad up front
if _, statErr := os.Stat(c.KubeconfigPath); statErr != nil {
    return nil, fmt.Errorf("kubeconfig path %q not accessible: %w; check --kubeconfig mount", c.KubeconfigPath, statErr)
}
clientConfig, err := clientcmd.LoadFromFile(c.KubeconfigPath)
if err != nil {
    return nil, fmt.Errorf("loading kubeconfig from file %q: %w", c.KubeconfigPath, err)
}
Defensive patterns

Strategy: validation

Validate before calling

// Run before calling createClientConfigFromFile / LoadFromFile.
func validateKubeconfigPath(path string) error {
    info, err := os.Stat(path)
    if err != nil {
        return fmt.Errorf("kubeconfig %q not accessible: %w", path, err)
    }
    if info.IsDir() {
        return fmt.Errorf("kubeconfig %q is a directory, expected a file", path)
    }
    return nil
}

Try / catch

clientConfig, err := clientcmd.LoadFromFile(c.KubeconfigPath)
if err != nil {
    return nil, fmt.Errorf("loading kubeconfig from file %q: %w", c.KubeconfigPath, err)
}

Prevention

When it happens

Trigger: Running `kubemark --morph kubelet` (or proxy) with --kubeconfig pointing at a path that does not exist, is a directory, is unreadable by the kubemark process, or contains YAML/JSON that clientcmd rejects (wrong schema, duplicate keys, truncated).

Common situations: The hollow-node pod's kubeconfig volume isn't mounted at /kubeconfig/kubeconfig; the benchmark manifest mounted the wrong secret; the kubeconfig was half-written by a failed bootstrap step; a typo in --kubeconfig.

Related errors


AI-assisted analysis of kubernetes/kubernetes@b882c60b40 (2026-08-07). Data as JSON: /api/errors/f98d8df983c158fb. Report an issue: GitHub.