{"record":{"id":"1aae35a8d12dee45","repo":"derailed/k9s","slug":"no-valid-selector-found-on-service-s","errorCode":null,"errorMessage":"no valid selector found on Service %s","messagePattern":"no valid selector found on Service (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/dao/svc.go","lineNumber":36,"sourceCode":"var (\n\t_ Accessor   = (*Service)(nil)\n\t_ Loggable   = (*Service)(nil)\n\t_ Controller = (*Service)(nil)\n)\n\n// Service represents a k8s service.\ntype Service struct {\n\tResource\n}\n\n// TailLogs tail logs for all pods represented by this Service.\nfunc (s *Service) TailLogs(ctx context.Context, opts *LogOptions) ([]LogChan, error) {\n\tsvc, err := s.GetInstance(opts.Path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(svc.Spec.Selector) == 0 {\n\t\treturn nil, fmt.Errorf(\"no valid selector found on Service %s\", opts.Path)\n\t}\n\n\treturn podLogs(ctx, svc.Spec.Selector, opts)\n}\n\n// Pod returns a pod victim by name.\nfunc (s *Service) Pod(fqn string) (string, error) {\n\tsvc, err := s.GetInstance(fqn)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn podFromSelector(s.Factory, svc.Namespace, svc.Spec.Selector)\n}\n\n// GetInstance returns a service instance.\nfunc (s *Service) GetInstance(fqn string) (*v1.Service, error) {\n\to, err := s.getFactory().Get(s.gvr, fqn, true, labels.Everything())","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/dao/svc.go#L18-L54","documentation":"Service.TailLogs finds backing pods through the Service's spec.selector label map. The error fires when spec.selector is empty, meaning the Service selects no pods itself and log streaming via the Service is impossible.","triggerScenarios":"Invoking TailLogs on a Service with an empty selector: ExternalName services, headless Services that only own DNS records, Services delegating endpoint management to an EndpointSlice/external controller (e.g. custom ingress or external-dns patterns), or manifests where the selector block was accidentally dropped.","commonSituations":"ExternalName services (sql.example.com style DB pointers); manually managed EndpointSlices; selecting such a Service in k9s and hitting the logs shortcut.","solutions":["Check the type and selector: kubectl get svc <name> -o yaml | grep -A4 selector","If pods should back it, fix the manifest: set spec.selector to the workload's labels and re-apply","For ExternalName or selector-less Services, tail logs from the actual workload (Deployment/Pod) instead","If endpoints are externally managed, find the target pods via kubectl get endpointslices -n <ns>"],"exampleFix":"# before: no selector\napiVersion: v1\nkind: Service\nmetadata:\n  name: api\nspec:\n  ports:\n  - port: 80\n# after: selector matching pods\napiVersion: v1\nkind: Service\nmetadata:\n  name: api\nspec:\n  selector:\n    app: api\n  ports:\n  - port: 80","handlingStrategy":"validation","validationCode":"svc, err := clientset.CoreV1().Services(ns).Get(ctx, name, metav1.GetOptions{})\nif err != nil { return err }\nif len(svc.Spec.Selector) == 0 {\n    return fmt.Errorf(\"service %s selects no pods (type=%s); tail logs from the workload instead\", name, svc.Spec.Type)\n}","typeGuard":"func selectsPods(svc *corev1.Service) bool {\n    return len(svc.Spec.Selector) > 0\n}","tryCatchPattern":"chans, err := svcDAO.TailLogs(ctx, opts)\nif err != nil {\n    if strings.Contains(err.Error(), \"no valid selector\") {\n        return errors.Join(err, fmt.Errorf(\"hint: ExternalName or selector-less Service has no pods\"))\n    }\n    return err\n}","preventionTips":["Check svc.spec.type before wiring log shortcuts; skip ExternalName services","Lint Services for a selector unless endpoints are managed externally"],"tags":["kubernetes","service","selector","logs","k9s"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}