GoogleContainerTools/skaffold · error

cannot resolve active Kubernetes context - multiple contexts

Error message

cannot resolve active Kubernetes context - multiple contexts configured in skaffold.yaml

What it means

getDefaultDeployer iterates all deploy configs in skaffold.yaml and collects a single active Kubernetes context. If two or more deploy configs declare different `kubeContext` values, no single deployer context can be chosen and this error is returned. Skaffold requires all deployers in a run to target the same cluster context.

Source

Thrown at pkg/skaffold/runner/deployer.go:244

  - deploy.Kubectl.Flags
  - deploy.Kubectl.DefaultNamespace

For a multi-config project, we do not currently support resolving conflicts between differing sets of this deploy configuration.
Therefore, in this function we do implicit validation of the provided configuration, and fail if any conflict cannot be resolved.
*/
func getDefaultDeployer(runCtx *runcontext.RunContext, labeller *label.DefaultLabeller, selectors []manifest.GroupKindSelector) (deploy.Deployer, error) {
	deployCfgs := runCtx.DeployConfigs()

	var kFlags *latest.KubectlFlags
	var logPrefix string
	var defaultNamespace *string
	var kubeContext string
	statusCheckTimeout := -1
	var statusCheck *bool
	for _, d := range deployCfgs {
		if d.KubeContext != "" {
			if kubeContext != "" && kubeContext != d.KubeContext {
				return nil, errors.New("cannot resolve active Kubernetes context - multiple contexts configured in skaffold.yaml")
			}
			kubeContext = d.KubeContext
		}
		if d.StatusCheck != nil {
			if statusCheck == nil {
				statusCheck = d.StatusCheck
			} else if statusCheck != d.StatusCheck {
				// if we get conflicting values for status check from different skaffold configs, we turn status check off
				statusCheck = util.Ptr(false)
			}
		}
		if d.StatusCheckDeadlineSeconds != 0 && d.StatusCheckDeadlineSeconds != int(status.DefaultStatusCheckDeadline.Seconds()) {
			if statusCheckTimeout != -1 && statusCheckTimeout != d.StatusCheckDeadlineSeconds {
				return nil, fmt.Errorf("found multiple status check timeouts in skaffold.yaml (not supported in `skaffold apply`): %d, %d", statusCheckTimeout, d.StatusCheckDeadlineSeconds)
			}
			statusCheckTimeout = d.StatusCheckDeadlineSeconds
		}
		if d.Logs.Prefix != "" {

View on GitHub (pinned to a1189de023)

Solutions

  1. Set the same `kubeContext` value on every deploy config in skaffold.yaml (or remove kubeContext from all of them to use kubectl's current context).
  2. Remove the redundant deploy config that points at the wrong cluster.
  3. Use the `--kube-context` CLI flag on a single-context config instead of hardcoding contexts in the file.

Example fix

// before
deploy:
  kubectl:
    kubeContext: minikube
  helm:
    kubeContext: gke_my-project_us-central1-c_my-cluster
// after
deploy:
  kubectl: {}
  helm: {}
# or set the same kubeContext on both
Defensive patterns

Strategy: validation

Validate before calling

yq e '.deploy | (.kubectl.kubeContext // "") , (.helm.kubeContext // "")' skaffold.yaml | sort -u | wc -l
# must be <= 1 (ignoring empty) before running skaffold

Type guard

func singleKubeContext(cfgs []*latest.DeployConfig) (string, bool) {
	var ctx string
	for _, d := range cfgs {
		if d.KubeContext == "" {
			continue
		}
		if ctx != "" && ctx != d.KubeContext {
			return "", false
		}
		ctx = d.KubeContext
	}
	return ctx, true
}

Prevention

When it happens

Trigger: Running any command that builds a deployer (GetDeployer / Dev / Deploy) with a skaffold.yaml containing multiple deploy configs (e.g. kubectl + helm) where each sets a different `deploy.kubeContext`.

Common situations: Developers combining a kubectl deploy stanza and a helm deploy stanza in one skaffold.yaml but pointing them at different clusters (e.g. `minikube` vs `gke_project_us-central1`), often after copy-pasting configs from different projects.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/5ef7ea951403cfb9. Report an issue: GitHub.