GoogleContainerTools/skaffold · error
getting service %s/%s: %w
Error message
getting service %s/%s: %w
What it means
After obtaining the client, findNewestPodForService fetches the Service object named serviceName in namespace ns. If the API server Get call fails, the error is wrapped as "getting service <ns>/<name>: <cause>". This wraps transport, auth, or not-found errors returned by client-go when reading the Service.
Source
Thrown at pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go:267
case err <- nil:
default:
}
}
}
}
}
// findNewestPodForService queries the cluster to find a pod that fulfills the given service, giving
// preference to pods that were most recently created. This is in contrast to the selection algorithm
// used by kubectl (see https://github.com/GoogleContainerTools/skaffold/issues/4522 for details).
func findNewestPodForService(ctx context.Context, kubeContext, ns, serviceName string, servicePort schemautil.IntOrString) (string, int, error) {
client, err := kubernetesclient.Client(kubeContext)
if err != nil {
return "", -1, fmt.Errorf("getting Kubernetes client: %w", err)
}
svc, err := client.CoreV1().Services(ns).Get(ctx, serviceName, metav1.GetOptions{})
if err != nil {
return "", -1, fmt.Errorf("getting service %s/%s: %w", ns, serviceName, err)
}
svcPort, err := findServicePort(*svc, servicePort)
if err != nil {
return "", -1, err
}
// Look for pods with matching selectors and that are not terminated.
// We cannot use field selectors as they are only supported in 1.16
// https://github.com/flant/shell-operator/blob/8fa3c3b8cfeb1ddb37b070b7a871561fdffe788b/HOOKS.md#fieldselector
set := labels.Set(svc.Spec.Selector)
listOptions := metav1.ListOptions{
LabelSelector: set.AsSelector().String(),
}
podsList, err := client.CoreV1().Pods(ns).List(ctx, listOptions)
if err != nil {
return "", -1, fmt.Errorf("listing pods: %w", err)
}
var pods []corev1.PodView on GitHub (pinned to a1189de023)
Solutions
- Check the service exists: `kubectl get svc <name> -n <namespace>` with the same kubeContext; deploy it if missing.
- Verify the namespace in the skaffold port-forward resource config matches where the service was created.
- Fix cluster connectivity/auth (`kubectl cluster-info`, re-authenticate).
- If RBAC, grant the user's identity `get` on services in that namespace.
Example fix
// before: forwarding resource names a service that is not deployed - resourceName: my-service namespace: default // after: deploy the service or use the correct name/namespace - resourceName: web-svc namespace: prod
Defensive patterns
Strategy: validation
Validate before calling
svc, err := client.CoreV1().Services(ns).Get(ctx, serviceName, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
return fmt.Errorf("service %s/%s does not exist yet; deploy it before port-forwarding", ns, serviceName)
} Type guard
func serviceExists(err error) bool {
return err == nil || !apierrors.IsNotFound(err)
} Try / catch
if _, err := findNewestPodForService(ctx, kubeContext, ns, svcName, port); err != nil {
if strings.Contains(err.Error(), "getting service") {
log.Warnf("service %s/%s unreachable: %v — is the app deployed?", ns, svcName, err)
}
} Prevention
- Always apply the manifests (or let skaffold deploy) before local port-forwarding.
- Double-check namespace and serviceName in port-forward resources with `kubectl get svc -A | grep <name>`.
- Use skaffold's dependencies so port-forward resources wait for deployed services.
When it happens
Trigger: client.CoreV1().Services(ns).Get(ctx, serviceName, metav1.GetOptions{}) returns an error: service does not exist (NotFound), namespace does not exist, RBAC denies services get, or the API server is unreachable/times out.
Common situations: Port-forwarding a service whose manifest was never applied (or was applied in a different namespace); typo'd serviceName in kubectl port-forward resources; cluster connectivity dropped mid-session; restricted RBAC in shared clusters.
Related errors
- patching resource %s/%q: %w
- getting server resources for group version: %w
- listing pods: %w
- STATUSCHECK_DEPLOYMENT_FETCH_ERR
- STATUSCHECK_STATEFULSET_FETCH_ERR
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/0eb70dd04f60e46c.
Report an issue: GitHub.