kubernetes/kops · error
failed to create host %s/%s: %w
Error message
failed to create host %s/%s: %w
What it means
After building the controller-runtime client, enrollHost creates the kops Host custom resource in the kops-system namespace on the target cluster. The error wraps the API server's rejection of that Create call, including its reason.
Source
Thrown at pkg/commands/toolbox_enroll.go:235
return fmt.Errorf("building kubernetes scheme: %w", err)
}
// Ensure that we don't try to use proto with our CRD
restConfigNoProto := rest.CopyConfig(restConfig)
restConfigNoProto.ContentType = runtime.ContentTypeJSON
restConfigNoProto.AcceptContentTypes = runtime.ContentTypeJSON
kubeClient, err := client.New(restConfigNoProto, client.Options{
Scheme: scheme,
})
if err != nil {
return fmt.Errorf("building kubernetes client: %w", err)
}
// We can't create the host resource in the API server for control-plane nodes,
// because the API server (likely) isn't running yet.
if !ig.IsControlPlane() {
if err := kubeClient.Create(ctx, hostData); err != nil {
return fmt.Errorf("failed to create host %s/%s: %w", hostData.Namespace, hostData.Name, err)
}
}
for k, v := range bootstrapData.NodeupScriptAdditionalFiles {
if err := sshTarget.writeFile(ctx, k, bytes.NewReader(v)); err != nil {
return fmt.Errorf("writing file %q over SSH: %w", k, err)
}
}
if len(bootstrapData.NodeupScript) != 0 {
if _, err := sshTarget.runScript(ctx, string(bootstrapData.NodeupScript), ExecOptions{Echo: true}); err != nil {
return err
}
}
return nil
}
const scriptCreateKey = `View on GitHub (pinned to 4c8573c808)
Solutions
- Check the wrapped error: if AlreadyExists, the host is registered — delete it first (kubectl -n kops-system delete host <name>) or proceed
- Confirm the Host CRD exists: kubectl get crd hosts.kops.k8s.io; if missing, upgrade/apply kops CRDs
- Verify RBAC: kubectl auth can-i create hosts.kops.k8s.io -n kops-system
- Confirm API server connectivity: kubectl get --raw /healthz
Example fix
// before
if err := kubeClient.Create(ctx, hostData); err != nil {
return fmt.Errorf("failed to create host %s/%s: %w", hostData.Namespace, hostData.Name, err)
}
// after
err = kubeClient.Create(ctx, hostData)
if err != nil {
if apierrors.IsAlreadyExists(err) {
klog.Infof("host %s/%s already registered", hostData.Namespace, hostData.Name)
} else {
return fmt.Errorf("failed to create host %s/%s: %w", hostData.Namespace, hostData.Name, err)
}
} Defensive patterns
Strategy: validation
Validate before calling
kubectl get crd hosts.kops.k8s.io && \ kubectl auth can-i create hosts.kops.k8s.io -n kops-system && \ kubectl get --raw /healthz
Type guard
func canCreateHosts(cfg *rest.Config) bool {
cl, err := discovery.NewForConfig(cfg)
if err != nil { return false }
res, err := cl.ServerResourcesForGroupVersion("kops.k8s.io/v1alpha2")
if err != nil { return false }
for _, r := range res.APIResources { return strings.Contains(r.Name, "hosts") }
return false
} Try / catch
err = kubeClient.Create(ctx, hostData)
if err != nil {
if apierrors.IsAlreadyExists(err) { klog.Info("host already registered") } else { return err }
} Prevention
- Pre-check the Host CRD exists before enrolling workers
- Handle AlreadyExists as idempotent rather than fatal
- Confirm RBAC with kubectl auth can-i before automating enroll
When it happens
Trigger: kubeClient.Create(ctx, hostData) returns an error: Host CRD not installed on the cluster, the Host with that namespace/name already exists (AlreadyExists), RBAC denies creating hosts, or the API server is unreachable.
Common situations: Enrolling a worker against a cluster where kops-controller CRDs are missing or an older kOps version, re-running enroll for a host that already registered, or insufficient user credentials against the admin API server.
Related errors
- error querying namespace %q: %v
- unable to find resource for %s: %w
- listing nodes in cluster: %v
- error listing nodes in cluster: %v
- error listing nodes: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/938d4919d56d7e5d.
Report an issue: GitHub.