GoogleContainerTools/skaffold · error
kubectl apply: %w
Error message
kubectl apply: %w
What it means
The kubectl deployer's Apply runs `kubectl apply -f -` with the rendered manifests. If kubectl exits non-zero, the error is wrapped in a userErr as 'kubectl apply'. This is the main deployment failure path: server-side validation, admission webhooks, or connectivity problems surface here.
Source
Thrown at pkg/skaffold/deploy/kubectl/cli.go:115
// TODO(dgageot): should we delete a manifest that was deployed and is not anymore?
updated := c.previousApply.Diff(manifests)
log.Entry(ctx).Debugf("%d manifests to deploy. %d are updated or new", len(manifests), len(updated))
if len(updated) == 0 {
return nil
}
args := []string{"-f", "-"}
if c.forceDeploy {
args = append(args, "--force", "--grace-period=0")
}
if c.Flags.DisableValidation {
args = append(args, "--validate=false")
}
if err := c.Run(ctx, updated.Reader(), out, "apply", c.args(c.Flags.Apply, args...)...); err != nil {
endTrace(instrumentation.TraceEndError(err))
return userErr(fmt.Errorf("kubectl apply: %w", err))
}
c.previousApply = manifests
return nil
}
type getResult struct {
Items []struct {
Metadata struct {
Name string `json:"name"`
DeletionTimestamp string `json:"deletionTimestamp"`
} `json:"metadata"`
} `json:"items"`
}
// WaitForDeletions waits for resource marked for deletion to complete their deletion.
func (c *CLI) WaitForDeletions(ctx context.Context, out io.Writer, manifests manifest.ManifestList) error {
if !c.waitForDeletions.Enabled {View on GitHub (pinned to a1189de023)
Solutions
- Re-run with the wrapped kubectl error visible and fix the offending manifest field (often server-side validation messages name the resource).
- Verify you're deploying to the intended context: `kubectl config current-context`.
- Check quotas, RBAC, and admission webhooks on the target namespace (`kubectl describe ns`, webhook logs).
- Temporarily test the exact manifests with `kubectl apply -f out/rendered.yaml` to iterate outside skaffold.
Example fix
// before: schema-invalid field spec: replicas: "3" // after spec: replicas: 3
Defensive patterns
Strategy: try-catch
Validate before calling
// Dry-run manifests against the cluster before real apply
if err := exec.Command("kubectl", "apply", "--dry-run=server", "-f", renderedFile).Run(); err != nil {
return fmt.Errorf("pre-apply validation failed: %w", err)
} Try / catch
if err := cli.Apply(ctx, out, manifests); err != nil {
if strings.Contains(err.Error(), "kubectl apply") {
log.Errorf("apply failed: %v\nInspect rendered yaml and server validation errors", err)
}
return err
} Prevention
- Validate hydrated manifests with `kubectl apply --dry-run=server` in CI
- Confirm the target context before deploying
- Check namespace quotas and admission webhook health
- Ensure images referenced exist in the registry before apply
When it happens
Trigger: c.Run for `kubectl apply` fails during Deploy — invalid manifest rejected by the API server, field validation errors, quota/admission webhook denials, image pull of non-existent registry, or auth/connection failure.
Common situations: Typo'd schema fields after hydration; namespace missing from cluster; admission webhook rejecting pods; deployment to wrong context; image tags never pushed.
Related errors
- %s: %s
- kubectl delete: %w
- %d resources failed to complete their deletion before a new
- kubectl create: %w
- unable to connect to Kubernetes: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/f82dfaf1adc2fa39.
Report an issue: GitHub.