derailed/k9s · warning
no matching pods for %v
Error message
no matching pods for %v
What it means
podFromSelector lists pods in a namespace with the given label selector and picks the first as the log/inspect target. When the list comes back empty, no pod backs the workload and this error names the selector that matched nothing.
Source
Thrown at internal/dao/svc.go:78
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &svc)
if err != nil {
return nil, errors.New("expecting Service resource")
}
return &svc, nil
}
// ----------------------------------------------------------------------------
// Helpers...
func podFromSelector(f Factory, ns string, sel map[string]string) (string, error) {
oo, err := f.List(client.PodGVR, ns, true, labels.Set(sel).AsSelector())
if err != nil {
return "", err
}
if len(oo) == 0 {
return "", fmt.Errorf("no matching pods for %v", sel)
}
var pod v1.Pod
err = runtime.DefaultUnstructuredConverter.FromUnstructured(oo[0].(*unstructured.Unstructured).Object, &pod)
if err != nil {
return "", err
}
return client.FQN(pod.Namespace, pod.Name), nil
}
View on GitHub (pinned to 2d3ccc6ba2)
Solutions
- Verify pods exist for the selector: kubectl get pods -n <ns> -l '<selector>'
- Compare the Service/workload selector with actual pod labels: kubectl get pods --show-labels
- Fix the label mismatch in the Service or workload template and re-apply
- If the workload is scaled to 0, scale it up: kubectl scale deploy <name> --replicas=1
Example fix
# selector typo before
spec:
selector:
app: Api # pods are labeled app: api
# after
spec:
selector:
app: api Defensive patterns
Strategy: validation
Validate before calling
pods, err := clientset.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: labels.Set(sel).AsSelector().String()})
if err != nil { return err }
if len(pods.Items) == 0 {
return fmt.Errorf("no pods match %v in %s — scale up the workload or fix labels", sel, ns)
} Try / catch
pod, err := svcDAO.Pod(fqn)
if err != nil && strings.Contains(err.Error(), "no matching pods") {
// don't retry: the workload has 0 pods; tell the user which selector failed
return fmt.Errorf("%w — verify with: kubectl get pods -n %s -l '%s'", err, ns, labels.Set(sel).AsSelector())
} Prevention
- Cross-check Service selectors against pod labels in CI (kubectl get pods --show-labels)
- Treat scaled-to-zero workloads as a known cause before debugging labels
When it happens
Trigger: Calling Service.Pod or any helper that resolves a workload to a single pod when zero pods carry the selector's labels: the backing Deployment/StatefulSet is scaled to 0, crashed pods were evicted, labels in the Service selector don't match pod template labels (typo like app: Api vs app: api), or the pods live in another namespace.
Common situations: Scaled-to-zero preview environments; label drift after chart upgrades renaming labels; crashed CrashLoopBackOff pods that were garbage-collected; selectors copied from a different namespace.
Related errors
- no valid selector found on deployment: %s
- no valid selector found on daemonset %q
- no valid selector found on statefulset: %s
- no valid selector found on Service %s
- user is not authorized to list pod metrics
AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15).
Data as JSON: /api/errors/707c5e2b069573a5.
Report an issue: GitHub.