{"record":{"id":"1d3131208d55e232","repo":"GoogleContainerTools/skaffold","slug":"service-q-does-not-expose-port-s","errorCode":null,"errorMessage":"service %q does not expose port %s","messagePattern":"service %q does not expose port (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go","lineNumber":333,"sourceCode":"\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}\n\t\tcase schemautil.String:\n\t\t\tif s.Name == servicePort.StrVal {\n\t\t\t\treturn s, nil\n\t\t\t}\n\t\t}\n\t}\n\treturn corev1.ServicePort{}, fmt.Errorf(\"service %q does not expose port %s\", svc.Name, servicePort.String())\n}\n\nfunc findTargetPort(svcPort corev1.ServicePort, pod corev1.Pod) int {\n\tif svcPort.TargetPort.Type == intstr.Int {\n\t\treturn svcPort.TargetPort.IntValue()\n\t}\n\tfor _, c := range pod.Spec.Containers {\n\t\tfor _, p := range c.Ports {\n\t\t\tif svcPort.TargetPort.StrVal == p.Name {\n\t\t\t\treturn int(p.ContainerPort)\n\t\t\t}\n\t\t}\n\t}\n\treturn -1\n}\n","sourceCodeStart":315,"sourceCodeEnd":349,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go#L315-L349","documentation":"findServicePort searches the service's spec.ports for a port matching the requested IntOrString (numeric or named). If no service port matches by number or name, it returns \"service %q does not expose port %s\". This is a configuration mismatch between the port the user asked to forward and the ports the Kubernetes Service actually declares.","triggerScenarios":"findServicePort(*svc, servicePort) iterates svc.Spec.Ports without matching: the requested numeric port is not in spec.ports[].port, or the requested string name does not equal any port's name.","commonSituations":"Port-forward config referencing the container port (e.g. 8080) instead of the service port (e.g. 80); referencing a named port that was renamed or omitted; multiple ports on the service and the wrong one requested; YAML edits that changed service ports after the skaffold config was written.","solutions":["Inspect the service's actual ports: `kubectl get svc <name> -o jsonpath='{.spec.ports}'` and request one of those ports (or its exact name) in the skaffold port-forward resource.","If you meant to forward the container/target port, use the service's exposed port number instead.","Add or rename the port in the Service manifest to match the requested name/number and redeploy.","When the service exposes multiple ports, specify the exact port or portName in the port-forward config."],"exampleFix":"// before: service exposes 80 but config forwards 8080\nport: 8080\n  localPort: 8080\n// after\nport: 80\n  localPort: 8080","handlingStrategy":"validation","validationCode":"svcObj, _ := client.CoreV1().Services(ns).Get(ctx, serviceName, metav1.GetOptions{})\nfor _, p := range svcObj.Spec.Ports {\n    if int32(requestedPort) == p.Port || requestedName == p.Name {\n        return nil // port is exposed by the service\n    }\n}\nreturn fmt.Errorf(\"service %s exposes ports %+v; requested %v not found\", serviceName, svcObj.Spec.Ports, requestedPort)","typeGuard":"func serviceExposesPort(svc corev1.Service, port schemautil.IntOrString) bool {\n    for _, p := range svc.Spec.Ports {\n        if port.Type == schemautil.Int && int32(port.IntVal) == p.Port { return true }\n        if port.Type == schemautil.String && port.StrVal == p.Name { return true }\n    }\n    return false\n}","tryCatchPattern":"if err := tryForward(ctx, svc, port); err != nil && strings.Contains(err.Error(), \"does not expose port\") {\n    log.Errorf(\"%v — run `kubectl get svc %s -o yaml` and pick a declared port\", err, svc)\n}","preventionTips":["Forward the service's declared port (spec.ports[].port or its name), not the container port.","Regenerate skaffold port-forward entries whenever service port definitions change.","For multi-port services, always set an explicit portName/port in the resource config.","Validate the config with `kubectl get svc <name> -o jsonpath='{.spec.ports}'` during code review."],"tags":["kubernetes","port-forward","config-mismatch"],"backgroundTag":"port-not-exposed","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"}