{"record":{"id":"018e596ec597f00a","repo":"GoogleContainerTools/skaffold","slug":"initializing-api-server-w","errorCode":null,"errorMessage":"initializing api server: %w","messagePattern":"initializing api server: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/skaffold/app/cmd/cmd.go","lineNumber":102,"sourceCode":"\t\t\tif cmd.Name() != cobra.ShellCompRequestCmd && cmd.Name() != cobra.ShellCompNoDescRequestCmd {\n\t\t\t\tinstrumentation.SetCommand(cmd.Name())\n\t\t\t\tout := output.GetWriter(context.Background(), out, defaultColor, forceColors, timestamps)\n\t\t\t\tcmd.Root().SetOut(out)\n\t\t\t\tcmd.Root().SetErr(errOut)\n\n\t\t\t\t// Setup logs\n\t\t\t\tif err := setUpLogs(errOut, v, timestamps); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Setup kubeContext and kubeConfig\n\t\t\tkubectx.ConfigureKubeConfig(opts.KubeConfig, opts.KubeContext)\n\n\t\t\t// Start API Server\n\t\t\tshutdown, err := server.Initialize(opts)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"initializing api server: %w\", err)\n\t\t\t}\n\t\t\tshutdownAPIServer = shutdown\n\n\t\t\t// Print version\n\t\t\tversionInfo := version.Get()\n\t\t\tversion.SetClient(opts.User)\n\t\t\tlog.Entry(context.TODO()).Infof(\"Skaffold %+v\", versionInfo)\n\t\t\tif !isHouseKeepingMessagesAllowed(cmd) {\n\t\t\t\tlog.Entry(context.TODO()).Debug(\"Disable housekeeping messages for command explicitly\")\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\t// Always perform all checks.\n\t\t\tgo func() {\n\t\t\t\tupdateMsg <- updateCheckForReleasedVersionsIfNotDisabled(versionInfo.Version)\n\t\t\t}()\n\t\t\tmetricsPrompt = prompt.ShouldDisplayMetricsPrompt(opts.GlobalConfig)\n\t\t\treturn nil\n\t\t},","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/cmd/skaffold/app/cmd/cmd.go#L84-L120","documentation":"In the shared skaffold command setup (cmd/skaffold/app/cmd/cmd.go:102), commands that enable the API server call server.Initialize(opts) after configuring the kube context. If the API server cannot be initialized (port binding failure, listener creation error, etc.), the command aborts with this error wrapping the cause.","triggerScenarios":"Running any command with --enable-api-server (or a command that starts it, like `skaffold dev`) where server.Initialize fails: the configured/mapped API server port is already in use, the port is privileged or unavailable, or the listener cannot be created.","commonSituations":"Another skaffold process or unrelated service already listening on the API server port; --api-server-port set to a port <1024 without privileges; firewall/SELinux blocking socket bind in restricted environments; stale skaffold process from a previous crashed session.","solutions":["Pick a free port via --api-server-port (check with `ss -ltnp` / `lsof -i :<port>`)","Kill the stale process holding the port (previous skaffold dev session)","Use a non-privileged port (>1024) if running without elevated permissions","Check firewall/SELinux policies if the bind is blocked even on a free port"],"exampleFix":"// before\n// skaffold dev --enable-api-server --api-server-port 80   # privileged/in-use\n// after\n// skaffold dev --enable-api-server --api-server-port 15051","handlingStrategy":"validation","validationCode":"// Check the API server port is free before starting\nport := 15051\nln, err := net.Listen(\"tcp\", fmt.Sprintf(\"127.0.0.1:%d\", port))\nif err != nil {\n    return fmt.Errorf(\"api server port %d busy: %w\", port, err)\n}\nln.Close()","typeGuard":null,"tryCatchPattern":"if err := skaffold.Dev(ctx); err != nil {\n    if strings.Contains(err.Error(), \"initializing api server\") {\n        log.Println(\"API server failed to start; pick another --api-server-port or kill the stale process\")\n    }\n    return err\n}","preventionTips":["Use a high, uncommon port (>1024) for --api-server-port","Clean up stale skaffold dev sessions that hold the port","In CI, allocate dynamic ports instead of hardcoding one","Verify socket bind permissions under firewalls/SELinux in restricted environments"],"tags":["api-server","port-binding","cli"],"backgroundTag":"port-already-in-use","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"}