portainer/portainer · error

must provide either a kubeconfig path or a server

Error message

must provide either a kubeconfig path or a server

What it means

Error "must provide either a kubeconfig path or a server" thrown in portainer/portainer.

Source

Thrown at pkg/libkubectl/client.go:46

		return nil, err
	}

	streams, _, out, _ := genericiooptions.NewTestIOStreams()

	return &Client{
		factory: util.NewFactory(configFlags),
		streams: streams,
		out:     out,
	}, nil
}

// generateConfigFlags generates the config flags for the kubectl client
// If kubeconfigPath is provided, it will be used instead of server and token
// If server and token are provided, they will be used to connect to the cluster
// If neither kubeconfigPath or server and token are provided, an error will be returned
func generateConfigFlags(token, server, namespace, kubeconfigPath string, insecure bool) (*genericclioptions.ConfigFlags, error) {
	if kubeconfigPath == "" && server == "" {
		return nil, errors.New("must provide either a kubeconfig path or a server")
	}

	// Pass 'false' to usePersistentConfig to prevent memory leaks.
	configFlags := genericclioptions.NewConfigFlags(false)
	if namespace != "" {
		configFlags.Namespace = &namespace
	}

	if kubeconfigPath != "" {
		configFlags.KubeConfig = &kubeconfigPath
	} else {
		configFlags.APIServer = &server
		configFlags.BearerToken = &token
	}

	configFlags.Insecure = &insecure

	return configFlags, nil

View on GitHub (pinned to 17e74456ff)

When it happens

Trigger: Thrown at pkg/libkubectl/client.go:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of portainer/portainer@17e74456ff (2026-08-26). Data as JSON: /api/errors/5477017a72f480d5. Report an issue: GitHub.