{"record":{"id":"f82dfaf1adc2fa39","repo":"GoogleContainerTools/skaffold","slug":"kubectl-apply-w","errorCode":null,"errorMessage":"kubectl apply: %w","messagePattern":"kubectl apply: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/kubectl/cli.go","lineNumber":115,"sourceCode":"\t// TODO(dgageot): should we delete a manifest that was deployed and is not anymore?\n\tupdated := c.previousApply.Diff(manifests)\n\tlog.Entry(ctx).Debugf(\"%d manifests to deploy. %d are updated or new\", len(manifests), len(updated))\n\tif len(updated) == 0 {\n\t\treturn nil\n\t}\n\n\targs := []string{\"-f\", \"-\"}\n\tif c.forceDeploy {\n\t\targs = append(args, \"--force\", \"--grace-period=0\")\n\t}\n\n\tif c.Flags.DisableValidation {\n\t\targs = append(args, \"--validate=false\")\n\t}\n\n\tif err := c.Run(ctx, updated.Reader(), out, \"apply\", c.args(c.Flags.Apply, args...)...); err != nil {\n\t\tendTrace(instrumentation.TraceEndError(err))\n\t\treturn userErr(fmt.Errorf(\"kubectl apply: %w\", err))\n\t}\n\tc.previousApply = manifests\n\n\treturn nil\n}\n\ntype getResult struct {\n\tItems []struct {\n\t\tMetadata struct {\n\t\t\tName              string `json:\"name\"`\n\t\t\tDeletionTimestamp string `json:\"deletionTimestamp\"`\n\t\t} `json:\"metadata\"`\n\t} `json:\"items\"`\n}\n\n// WaitForDeletions waits for resource marked for deletion to complete their deletion.\nfunc (c *CLI) WaitForDeletions(ctx context.Context, out io.Writer, manifests manifest.ManifestList) error {\n\tif !c.waitForDeletions.Enabled {","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/kubectl/cli.go#L97-L133","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typo'd schema fields after hydration; namespace missing from cluster; admission webhook rejecting pods; deployment to wrong context; image tags never pushed.","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."],"exampleFix":"// before: schema-invalid field\nspec:\n  replicas: \"3\"\n// after\nspec:\n  replicas: 3","handlingStrategy":"try-catch","validationCode":"// Dry-run manifests against the cluster before real apply\nif err := exec.Command(\"kubectl\", \"apply\", \"--dry-run=server\", \"-f\", renderedFile).Run(); err != nil {\n    return fmt.Errorf(\"pre-apply validation failed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := cli.Apply(ctx, out, manifests); err != nil {\n    if strings.Contains(err.Error(), \"kubectl apply\") {\n        log.Errorf(\"apply failed: %v\\nInspect rendered yaml and server validation errors\", err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["kubectl","kubernetes","apply","deployment"],"backgroundTag":"kubectl-apply-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}