kubernetes/kops · error
must specify a cluster when creating additional objects
Error message
must specify a cluster when creating additional objects
What it means
Unstructured add-on objects cannot be attached to any cluster by themselves; RunCreate requires that at least one Cluster was created in the same `kops create -f` invocation. With addons present and zero clusters created, it returns this error instead of guessing a target.
Source
Thrown at cmd/kops/create.go:222
case *unstructured.Unstructured:
addons = append(addons, kubemanifest.NewObject(v.Object))
default:
klog.V(2).Infof("Type of object was %T", v)
return fmt.Errorf("unhandled kind %q in %s", gvk, f)
}
}
}
// Because not all addons support labels, we can only support one cluster here.
// A single cluster per create is probably a good idea anyway.
if len(addons) != 0 {
if len(clusters) > 1 {
return fmt.Errorf("cannot specify additional objects when multiple clusters are created")
}
if len(clusters) == 0 {
return fmt.Errorf("must specify a cluster when creating additional objects")
}
cluster := clusters[0]
addonsClient := clientset.AddonsFor(cluster)
if err := addonsClient.Replace(addons); err != nil {
return fmt.Errorf("error writing additional objects: %v", err)
}
}
{
// If there is a value in this sb, this should mean that we have something to deploy
// so let's advise the user how to engage the cloud provider and deploy
if sb.String() != "" {
fmt.Fprintf(&sb, "\n")
fmt.Fprintf(&sb, "To deploy these resources, run: kops update cluster --name %s --yes\n", clusterName)
fmt.Fprintf(&sb, "\n")
}View on GitHub (pinned to 4c8573c808)
Solutions
- Include the Cluster document in the same -f file when creating addons with `kops create`
- Use `kops replace -f addons.yaml` to apply add-ons to an existing cluster
- Create the cluster first, then pass add-ons in a subsequent `kops create -f` that also (re)includes the cluster, or use apply/replace
Example fix
// before kops create -f addons.yaml // after kops replace -f addons.yaml # addons against existing cluster
Defensive patterns
Strategy: validation
Validate before calling
clusters, addons := classify(docs)
if len(addons) > 0 && len(clusters) == 0 {
return fmt.Errorf("add-on objects require a Cluster in the same create, or use kops replace")
} Prevention
- Use `kops replace -f` for add-ons against existing clusters
- Include the Cluster document when using `kops create -f` for addons
- Document in tooling that create is for new clusters, not incremental addon pushes
When it happens
Trigger: `kops create -f addons.yaml` containing only unstructured manifests (no kind: Cluster section) while the cluster already exists or was created in an earlier run.
Common situations: Applying add-on manifests against an existing cluster using `create` instead of `replace`; forgetting to include the Cluster document; automation assuming create can add addons to an existing cluster.
Related errors
- cannot specify additional objects when multiple clusters are
- building menu for %q: %w
- applying %q: %w
- must specify %q label with cluster name to create instanceGr
- error querying cluster %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/e05bec0cc3f256f0.
Report an issue: GitHub.