{"record":{"id":"e29f05242f790a1e","repo":"derailed/k9s","slug":"pod-must-be-running-current-status-v","errorCode":null,"errorMessage":"pod must be running. Current status=%v","messagePattern":"pod must be running\\. Current status=(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/view/pf_extender.go","lineNumber":125,"sourceCode":"\nfunc (p *PortForwardExtender) portForwardContext(ctx context.Context) context.Context {\n\tif bc := p.App().BenchFile; bc != \"\" {\n\t\tctx = context.WithValue(ctx, internal.KeyBenchCfg, p.App().BenchFile)\n\t}\n\n\treturn context.WithValue(ctx, internal.KeyPath, p.GetTable().GetSelectedItem())\n}\n\n// ----------------------------------------------------------------------------\n// Helpers...\n\nfunc ensurePodPortFwdAllowed(factory dao.Factory, podName string) error {\n\tpod, err := fetchPod(factory, podName)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif pod.Status.Phase != v1.PodRunning {\n\t\treturn fmt.Errorf(\"pod must be running. Current status=%v\", pod.Status.Phase)\n\t}\n\n\treturn nil\n}\n\nfunc runForward(v ResourceViewer, pf watch.Forwarder, f *portforward.PortForwarder) {\n\tv.App().factory.AddForwarder(pf)\n\n\tv.App().QueueUpdateDraw(func() {\n\t\tDismissPortForwards(v, v.App().Content.Pages)\n\t})\n\n\tpf.SetActive(true)\n\tif err := f.ForwardPorts(); err != nil {\n\t\tv.App().Flash().Warnf(\"PortForward failed for %s: %s. Deleting!\", pf.ID(), err)\n\t}\n\tv.App().QueueUpdateDraw(func() {\n\t\tv.App().factory.DeleteForwarder(pf.ID())","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/pf_extender.go#L107-L143","documentation":"ensurePodPortFwdAllowed (internal/view/pf_extender.go:125) fetches the pod and rejects the operation unless pod.Status.Phase == v1.PodRunning. The Kubernetes portforward API requires an active sandbox, which only exists once the pod is Running. The message reports the actual phase (Pending, Succeeded, Failed, Unknown).","triggerScenarios":"Starting a port-forward on a pod that is Pending (still pulling images / scheduling), Succeeded or Failed (Job pods), or Unknown (lost node). Also triggered by forwarding from a Deployment/StatefulSet immediately after creation before the pod transitions to Running.","commonSituations":"Rollouts in progress: user hits shift+f right after kubectl apply; completed/failed Job pods that still appear in the pod list; CrashLoopBackOff pods whose phase is Running intermittently (this one passes the phase check but fails later); node not ready.","solutions":["Wait for the pod to reach Running (watch 'kubectl get pod <name> -w' until STATUS=Running) and retry","If the pod is Succeeded/Failed (Job), rerun the Job or forward to a pod from an active workload","Check events for scheduling/image problems: 'kubectl describe pod <name>' (ImagePullBackOff, Pending reasons)","For multi-replica workloads, forward from a replica that is Running instead of the one selected"],"exampleFix":"// before: port-forward while pod is Pending\n// -> pod must be running. Current status=Pending\n\n# after: wait for Running, then retry\nkubectl get pod mypod -w   # wait for STATUS=Running\n# in k9s: shift+f again","handlingStrategy":"validation","validationCode":"// check pod phase before attempting a forward\npod, err := fetchPod(factory, podName)\nif err != nil { return err }\nif pod.Status.Phase != v1.PodRunning {\n    return fmt.Errorf(\"pod is %s; wait for Running before port-forwarding\", pod.Status.Phase)\n}","typeGuard":null,"tryCatchPattern":"// if calling the k8s portforward API directly, expect SPDY errors on non-running pods and re-check phase\nif err := pf.Start(); err != nil {\n    if pod, perr := fetchPod(factory, podName); perr == nil && pod.Status.Phase != v1.PodRunning {\n        return fmt.Errorf(\"pod not Running (%s): %w\", pod.Status.Phase, err)\n    }\n    return err\n}","preventionTips":["Watch pod phase before pressing shift+f (k9s shows STATUS in the pod table)","In automation, poll until phase==Running with a timeout instead of forwarding immediately after apply","Remember Succeeded/Failed Job pods never become Running — rerun the Job instead"],"tags":["k9s","port-forward","kubernetes","pod-phase","validation"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}