GoogleContainerTools/skaffold · error

instantiating default kubectl deployer: %w

Error message

instantiating default kubectl deployer: %w

What it means

Wraps any error returned when Skaffold constructs its default kubectl deployer during `skaffold apply`/`deploy` fallback. kubectl.NewDeployer fails if the kubectl deploy config or its flags are invalid (e.g. bad kube-context values, invalid flags). The inner error identifies the concrete problem.

Source

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

		}
		if currentDefaultNamespace != nil {
			if defaultNamespace != nil && *defaultNamespace != *currentDefaultNamespace {
				return nil, fmt.Errorf("found multiple namespaces in skaffold.yaml (not supported in `skaffold apply`): %s, %s", *defaultNamespace, *currentDefaultNamespace)
			}
			defaultNamespace = currentDefaultNamespace
		}
	}
	if kFlags == nil {
		kFlags = &latest.KubectlFlags{}
	}
	k := &latest.KubectlDeploy{
		Flags:            *kFlags,
		DefaultNamespace: defaultNamespace,
	}
	dCtx := &deployerCtx{runCtx, latest.DeployConfig{StatusCheck: statusCheck, KubeContext: kubeContext, DeployType: latest.DeployType{KubectlDeploy: k}}}
	defaultDeployer, err := kubectl.NewDeployer(dCtx, labeller, k, runCtx.Artifacts(), "", selectors)
	if err != nil {
		return nil, fmt.Errorf("instantiating default kubectl deployer: %w", err)
	}
	return defaultDeployer, nil
}

func validateKubectlFlags(flags *latest.KubectlFlags, additional latest.KubectlFlags) error {
	errStr := "conflicting sets of kubectl deploy flags not supported in `skaffold apply` (flag: %s)"
	if additional.DisableValidation != flags.DisableValidation {
		return fmt.Errorf(errStr, strconv.FormatBool(additional.DisableValidation))
	}
	for _, flag := range additional.Apply {
		if !stringslice.Contains(flags.Apply, flag) {
			return fmt.Errorf(errStr, flag)
		}
	}
	for _, flag := range additional.Delete {
		if !stringslice.Contains(flags.Delete, flag) {
			return fmt.Errorf(errStr, flag)
		}

View on GitHub (pinned to a1189de023)

Solutions

  1. Read the inner `%w` error to identify the concrete constructor failure
  2. Fix the deploy.kubectl section of skaffold.yaml (flags, kube-context)
  3. Run `skaffold config list` / `kubectl config get-contexts` to verify the kube-context exists
  4. Upgrade or match the Skaffold version used to author the config

Example fix

// before
deploy:
  kubectl:
    flags:
      apply: ["--unknown-flag"]
// after
deploy:
  kubectl:
    flags:
      apply: ["--server-side"]
Defensive patterns

Strategy: validation

Validate before calling

// pre-check kubectl deploy config before apply
const k = cfg.deploy?.kubectl
if (k?.flags?.apply || k?.flags?.delete || k?.flags?.global) {
  for (const f of [...(k.flags.apply||[]), ...(k.flags.delete||[]), ...(k.flags.global||[])])
    if (!f.startsWith('--')) throw new Error(`invalid kubectl flag: ${f}`)
}
if (k?.kubeContext && !knownContexts.includes(k.kubeContext)) throw new Error(`unknown kube-context: ${k.kubeContext}`)

Type guard

function hasValidKubectlConfig(c) {
  return c != null && typeof c === 'object' &&
    (c.kubectl == null || typeof c.kubectl === 'object')
}

Try / catch

deployer, err := kubectl.NewDeployer(dCtx, labeller, k, artifacts, "", selectors)
if err != nil {
    log.Errorf("kubectl deployer init failed: %v", err)
    return fmt.Errorf("check deploy.kubectl config: %w", err)
}

Prevention

When it happens

Trigger: getDefaultDeployer calls kubectl.NewDeployer with the parsed kubectl deploy config and flag selectors; any non-nil error from that constructor (invalid kubeContext, malformed flags, artifact issues) is wrapped here.

Common situations: Invalid `deploy.kubectl.flags` in skaffold.yaml; unsupported/renamed kubectl flag; corrupted kubeconfig referenced by the kube-context; running `skaffold apply` on a config last written by a different Skaffold version.

Related errors


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