{"record":{"id":"9aedf9e31bd46126","repo":"GoogleContainerTools/skaffold","slug":"kubectl-create-w","errorCode":null,"errorMessage":"kubectl create: %w","messagePattern":"kubectl create: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/kubectl/cli.go","lineNumber":227,"sourceCode":"\t\tdryRun += \"=client\"\n\t}\n\n\targs := c.args([]string{dryRun, \"-oyaml\"}, list...)\n\n\tif c.Flags.DisableValidation {\n\t\targs = append(args, \"--validate=false\")\n\t}\n\targsWithoutNamespace := args\n\tif ns := util.ParseNamespaceFromFlags(c.Flags.Apply); ns != \"\" {\n\t\targs = append(args, \"-n\", ns)\n\t}\n\n\tbuf, err := c.RunOut(ctx, \"create\", args...)\n\tif err != nil {\n\t\t// try running again without the `--namespace` flag\n\t\tbuf, err = c.RunOutWithoutNamespace(ctx, \"create\", argsWithoutNamespace...)\n\t\tif err != nil {\n\t\t\treturn nil, readManifestErr(fmt.Errorf(\"kubectl create: %w\", err))\n\t\t}\n\t}\n\n\tvar manifestList manifest.ManifestList\n\tmanifestList.Append(buf)\n\n\treturn manifestList, nil\n}\n\nfunc (c *CLI) args(commandFlags []string, additionalArgs ...string) []string {\n\targs := make([]string, 0, len(c.Flags.Global)+len(commandFlags)+len(additionalArgs))\n\n\targs = append(args, c.Flags.Global...)\n\targs = append(args, commandFlags...)\n\targs = append(args, additionalArgs...)\n\n\treturn args\n}","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/kubectl/cli.go#L209-L245","documentation":"The kubectl deployer uses `kubectl create --dry-run=client -o yaml` (ReadManifests) to materialize manifests with defaults (including namespace) before deploying. If the create command fails — including on a retry without the --namespace flag — this readManifestErr is returned. Usually the failure is a bad kubeconfig, unreachable cluster for validation, or unsupported flag combination.","triggerScenarios":"Both `c.RunOut(create args...)` and `c.RunOutWithoutNamespace(create argsWithoutNamespace...)` fail — e.g. kubectl can't resolve the current context/namespace, the --namespace flag is rejected by an old kubectl, or a referenced file (kustomize/-f path) is missing.","commonSituations":"Current kubeconfig context has no default namespace and dry-run needs it; very old kubectl binaries lacking client dry-run flags; malformed manifest files passed via skaffold kubectl deployer config.","solutions":["Read the wrapped root cause; run the equivalent `kubectl create --dry-run=client -o yaml -f <manifest>` manually to see the full message.","Upgrade kubectl to a recent version matching your cluster (client dry-run features).","Fix kubeconfig: ensure the current context has a valid namespace or set one explicitly.","Verify all manifest paths referenced by the deploy config exist."],"exampleFix":"// before\n$ skaffold deploy  # kubectl create fails: no namespace in context\n// after\nkubectl config set-context --current --namespace=default\n$ skaffold deploy","handlingStrategy":"validation","validationCode":"// Ensure context and namespace resolve before reading manifests\nctxName, _ := exec.Command(\"kubectl\", \"config\", \"current-context\").Output()\nns, _ := exec.Command(\"kubectl\", \"config\", \"view\", \"--minify\", \"-ojsonpath={..namespace}\").Output()\nif strings.TrimSpace(string(ns)) == \"\" {\n    return fmt.Errorf(\"context %s has no default namespace\", ctxName)\n}","typeGuard":null,"tryCatchPattern":"if _, err := cli.ReadManifests(ctx, out, files, ns); err != nil {\n    if strings.Contains(err.Error(), \"kubectl create\") {\n        log.Errorf(\"manifest read failed: %v — verify kubeconfig and kubectl version\", err)\n    }\n    return err\n}","preventionTips":["Keep kubectl at a recent version supporting client-side dry-run","Ensure the current kube context has a default namespace","Verify all manifest file paths exist before deploy","Test `kubectl create --dry-run=client -o yaml -f ...` manually when debugging"],"tags":["kubectl","kubernetes","dry-run","manifests"],"backgroundTag":"kubectl-command-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"}