kubernetes/kops · error
failed to initialize the service controller, error: %v
Error message
failed to initialize the service controller, error: %v
What it means
Wraps a failure of watchers.NewServiceController during dns-controller startup. The controller that watches Service objects for DNS records could not be constructed, so the watcher set cannot be initialized and the process exits.
Source
Thrown at dns-controller/cmd/dns-controller/main.go:168
}
// initializeWatchers is responsible for creating the watchers
func initializeWatchers(client kubernetes.Interface, dnsctl *dns.DNSController, namespace string, watchIngress bool, internalRecordTypes []dns.RecordType) error {
klog.V(1).Infof("initializing the watch controllers, namespace: %q", namespace)
nodeController, err := watchers.NewNodeController(client, dnsctl, internalRecordTypes)
if err != nil {
return fmt.Errorf("failed to initialize the node controller, error: %v", err)
}
podController, err := watchers.NewPodController(client, dnsctl, namespace)
if err != nil {
return fmt.Errorf("failed to initialize the pod controller, error: %v", err)
}
serviceController, err := watchers.NewServiceController(client, dnsctl, namespace)
if err != nil {
return fmt.Errorf("failed to initialize the service controller, error: %v", err)
}
var ingressController *watchers.IngressController
if watchIngress {
ingressController, err = watchers.NewIngressController(client, dnsctl, namespace)
if err != nil {
return fmt.Errorf("failed to initialize the ingress controller, error: %v", err)
}
} else {
klog.Infof("Ingress controller disabled")
}
go nodeController.Run()
go podController.Run()
go serviceController.Run()
if watchIngress {
go ingressController.Run()View on GitHub (pinned to 4c8573c808)
Solutions
- Inspect the wrapped underlying error text.
- Verify RBAC and kubeconfig allow listing/watching services in the target namespace.
- Correct the --namespace flag or omit it to watch all namespaces.
Example fix
// before
serviceController, err := watchers.NewServiceController(nil, dnsctl, ns)
// after
if client == nil { klog.Fatalf("nil kubernetes client") }
serviceController, err := watchers.NewServiceController(client, dnsctl, ns) Defensive patterns
Strategy: try-catch
Validate before calling
if client == nil || dnsctl == nil {
return errors.New("client and dns controller must be non-nil before NewServiceController")
} Type guard
func canBuildControllers(client kubernetes.Interface, dnsctl *dns.DNSController) bool {
return client != nil && dnsctl != nil
} Try / catch
if err := initializeWatchers(client, dnsctl, ns, watchIngress, types); err != nil {
klog.Fatalf("failed to init watchers: %v", err)
} Prevention
- Verify RBAC (list/watch services) with the same identity dns-controller runs as.
- Initialize the DNS controller before any watcher construction.
- Test controller constructors against a client-go fake clientset.
When it happens
Trigger: NewServiceController is called with a nil/invalid client, nil DNS controller, or invalid namespace and returns an error.
Common situations: Malformed kubeconfig or missing RBAC preventing client setup; invalid --namespace value; corrupted build/binary passing bad arguments.
Related errors
- failed to initialize the node controller, error: %v
- failed to initialize the pod controller, error: %v
- failed to initialize the ingress controller, error: %v
- error initializing DNS cache: %v
- error listing nodes: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/e04fb7b3f24595b7.
Report an issue: GitHub.