{"record":{"id":"4a572d61bdeff8ad","repo":"GoogleContainerTools/skaffold","slug":"no-pods-match-service-s-s","errorCode":null,"errorMessage":"no pods match service %s/%s","messagePattern":"no pods match service (.+?)/(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go","lineNumber":308,"sourceCode":"\t}\n\tsort.Slice(pods, newestPodsFirst(pods))\n\n\tif log.IsTraceLevelEnabled() {\n\t\tvar names []string\n\t\tfor _, p := range pods {\n\t\t\tnames = append(names, fmt.Sprintf(\"(pod:%q phase:%v created:%v)\", p.Name, p.Status.Phase, p.CreationTimestamp))\n\t\t}\n\t\tlog.Entry(ctx).Tracef(\"service %s/%s maps to %d pods: %v\", serviceName, servicePort.String(), len(pods), names)\n\t}\n\n\tfor _, p := range pods {\n\t\tif targetPort := findTargetPort(svcPort, p); targetPort > 0 {\n\t\t\tlog.Entry(ctx).Debugf(\"Forwarding service %s/%s to pod %s/%d\", serviceName, servicePort.String(), p.Name, targetPort)\n\t\t\treturn p.Name, targetPort, nil\n\t\t}\n\t}\n\n\treturn \"\", -1, fmt.Errorf(\"no pods match service %s/%s\", serviceName, servicePort.String())\n}\n\n// newestPodsFirst sorts pods by their creation time\nfunc newestPodsFirst(pods []corev1.Pod) func(int, int) bool {\n\treturn func(i, j int) bool {\n\t\tti := pods[i].CreationTimestamp.Time\n\t\ttj := pods[j].CreationTimestamp.Time\n\t\treturn ti.After(tj)\n\t}\n}\n\nfunc findServicePort(svc corev1.Service, servicePort schemautil.IntOrString) (corev1.ServicePort, error) {\n\tfor _, s := range svc.Spec.Ports {\n\t\tswitch servicePort.Type {\n\t\tcase schemautil.Int:\n\t\t\tif s.Port == int32(servicePort.IntVal) {\n\t\t\t\treturn s, nil\n\t\t\t}","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go#L290-L326","documentation":"The pods were listed successfully, but none of the Pending/Running pods had a target port matching the service port, or the list was empty. Skaffold throws \"no pods match service <ns>/<name>\" because it cannot find a concrete pod to forward traffic to. Unlike kubectl, it requires a matching healthy pod that exposes the service's target port.","triggerScenarios":"Pods list is empty (selector matches nothing or pods are Failed/Succeeded/terminating), or for every candidate pod findTargetPort(svcPort, pod) returns <= 0 because the pod's containerPort does not include the service's targetPort.","commonSituations":"Deploy still in progress and pods not yet Pending/Running; pod CrashLoopBackOff so only Failed pods exist; service selector labels don't match pod labels; targetPort in the service doesn't match any containerPort in the pod spec; using a LocalService/headless service with no backing pods.","solutions":["Verify pods are healthy: `kubectl get pods -n <ns> -l <svc-selector>`; wait for Pending/Running or fix crashes (check `kubectl logs`, `kubectl describe pod`).","Compare service spec.selector with the pod template labels and align them.","Confirm the service's targetPort matches a containerPort declared in the deployment's container spec.","Ensure the deployment is actually applied before/during skaffold dev."],"exampleFix":"// before: selector mismatch\n// service selector: app: web ; pod labels: app: webfrontend\nselector:\n  app: webfrontend\n// after: align labels\nselector:\n  app: web","handlingStrategy":"validation","validationCode":"selector := labels.Set(svc.Spec.Selector).AsSelector()\npods, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.String()})\nif err == nil && len(pods.Items) == 0 {\n    return fmt.Errorf(\"selector %q in ns %s matches no pods; check deployment labels and pod phase\", selector.String(), ns)\n}","typeGuard":"func hasForwardablePod(pods []corev1.Pod) bool {\n    for _, p := range pods {\n        if p.Status.Phase == corev1.PodPending || p.Status.Phase == corev1.PodRunning {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":"pod, port, err := findNewestPodForService(ctx, kubeContext, ns, svc, p)\nif errors.Is(err, errNoPodsMatch) || strings.Contains(err.Error(), \"no pods match\") {\n    log.Warnf(\"waiting for pods of %s/%s to become ready; will retry\", ns, svc)\n    // re-check after deployment settles or fall back to kubectl port-forward\n}","preventionTips":["Keep service spec.selector identical to the deployment's pod template labels.","Ensure every requested targetPort exists as a containerPort in the pod spec.","Only port-forward services whose backing pods reach Running/Ready; check `kubectl get pods -l <selector>` first.","Let skaffold deploy finish before attaching port-forward resources."],"tags":["kubernetes","port-forward","selector-mismatch"],"backgroundTag":"no-pods-match-selector","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"}