GoogleContainerTools/skaffold · error

no pods match service %s/%s

Error message

no pods match service %s/%s

What it means

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.

Source

Thrown at pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go:308

	}
	sort.Slice(pods, newestPodsFirst(pods))

	if log.IsTraceLevelEnabled() {
		var names []string
		for _, p := range pods {
			names = append(names, fmt.Sprintf("(pod:%q phase:%v created:%v)", p.Name, p.Status.Phase, p.CreationTimestamp))
		}
		log.Entry(ctx).Tracef("service %s/%s maps to %d pods: %v", serviceName, servicePort.String(), len(pods), names)
	}

	for _, p := range pods {
		if targetPort := findTargetPort(svcPort, p); targetPort > 0 {
			log.Entry(ctx).Debugf("Forwarding service %s/%s to pod %s/%d", serviceName, servicePort.String(), p.Name, targetPort)
			return p.Name, targetPort, nil
		}
	}

	return "", -1, fmt.Errorf("no pods match service %s/%s", serviceName, servicePort.String())
}

// newestPodsFirst sorts pods by their creation time
func newestPodsFirst(pods []corev1.Pod) func(int, int) bool {
	return func(i, j int) bool {
		ti := pods[i].CreationTimestamp.Time
		tj := pods[j].CreationTimestamp.Time
		return ti.After(tj)
	}
}

func findServicePort(svc corev1.Service, servicePort schemautil.IntOrString) (corev1.ServicePort, error) {
	for _, s := range svc.Spec.Ports {
		switch servicePort.Type {
		case schemautil.Int:
			if s.Port == int32(servicePort.IntVal) {
				return s, nil
			}

View on GitHub (pinned to a1189de023)

Solutions

  1. 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`).
  2. Compare service spec.selector with the pod template labels and align them.
  3. Confirm the service's targetPort matches a containerPort declared in the deployment's container spec.
  4. Ensure the deployment is actually applied before/during skaffold dev.

Example fix

// before: selector mismatch
// service selector: app: web ; pod labels: app: webfrontend
selector:
  app: webfrontend
// after: align labels
selector:
  app: web
Defensive patterns

Strategy: validation

Validate before calling

selector := labels.Set(svc.Spec.Selector).AsSelector()
pods, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.String()})
if err == nil && len(pods.Items) == 0 {
    return fmt.Errorf("selector %q in ns %s matches no pods; check deployment labels and pod phase", selector.String(), ns)
}

Type guard

func hasForwardablePod(pods []corev1.Pod) bool {
    for _, p := range pods {
        if p.Status.Phase == corev1.PodPending || p.Status.Phase == corev1.PodRunning {
            return true
        }
    }
    return false
}

Try / catch

pod, port, err := findNewestPodForService(ctx, kubeContext, ns, svc, p)
if errors.Is(err, errNoPodsMatch) || strings.Contains(err.Error(), "no pods match") {
    log.Warnf("waiting for pods of %s/%s to become ready; will retry", ns, svc)
    // re-check after deployment settles or fall back to kubectl port-forward
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/4a572d61bdeff8ad. Report an issue: GitHub.