openimsdk/open-im-server · error
service %s has no ports defined
Error message
service %s has no ports defined
What it means
After fetching the Service, getServicePort requires at least one port in svc.Spec.Ports. A Service with no ports cannot expose gRPC endpoints, so the lookup fails with this message. This is a Service manifest problem, not an API problem.
Source
Thrown at pkg/common/discovery/kubernetes/kubernetes.go:225
func (k *KubernetesConnManager) UnRegister() error {
return nil
}
func (k *KubernetesConnManager) GetUserIdHashGatewayHost(ctx context.Context, userId string) (string, error) {
return "", nil
}
func (k *KubernetesConnManager) getServicePort(serviceName string) (int32, error) {
var svcPort int32
svc, err := k.clientset.CoreV1().Services(k.namespace).Get(context.Background(), serviceName, metav1.GetOptions{})
if err != nil {
fmt.Print("namespace:", k.namespace)
return 0, fmt.Errorf("failed to get service %s: %v", serviceName, err)
}
if len(svc.Spec.Ports) == 0 {
return 0, fmt.Errorf("service %s has no ports defined", serviceName)
}
for _, port := range svc.Spec.Ports {
// fmt.Println(serviceName, " Now Get Port:", port.Port)
if port.Port != 10001 {
svcPort = port.Port
break
}
}
return svcPort, nil
}
// watchEndpoints listens for changes in Pod resources.
func (k *KubernetesConnManager) watchEndpoints() {
informerFactory := informers.NewSharedInformerFactory(k.clientset, time.Minute*10)
informer := informerFactory.Core().V1().Pods().Informer()
View on GitHub (pinned to 175a7bb067)
Solutions
- Add a ports section to the Service manifest mapping the gRPC container port (e.g. port 10001 or the app port).
- Redeploy/patch: kubectl patch svc <name> -p '{"spec":{"ports":[{"port":10001,"targetPort":10001}]}}'.
- Confirm the right Service is selected — a similarly named placeholder Service may be shadowing the real one.
Example fix
// before (Service yaml)
spec:
selector:
app: my-rpc
// after
spec:
selector:
app: my-rpc
ports:
- port: 10001
targetPort: 10001 Defensive patterns
Strategy: validation
Validate before calling
svc, _ := clientset.CoreV1().Services(ns).Get(ctx, svcName, metav1.GetOptions{})
if len(svc.Spec.Ports) == 0 {
return errors.New("service manifest has no ports")
} Prevention
- Lint Service manifests for a non-empty spec.ports before deploy
- Add a CI check that every gRPC service exposes its port mapping
- Avoid creating placeholder Services without ports
When it happens
Trigger: getServicePort reads a Service whose Spec.Ports is empty — the Service object exists but defines no port mappings.
Common situations: Hand-written or templated Service manifest missing the ports section; ExternalName/headless services created without ports; applying a stripped-down Service for metric-only exposure.
Related errors
- failed to create in-cluster config: %v
- failed to create clientset: %v
- config field %s %s not found
- no command to run
- standalone api port is 0
AI-assisted analysis of openimsdk/open-im-server@175a7bb067 (2026-09-04).
Data as JSON: /api/errors/7e785594250e40c6.
Report an issue: GitHub.