kubernetes/kops · error

could not find instance %v

Error message

could not find instance %v

What it means

RunDeleteInstance returns this when findDeletionNode scans all cloud instance groups (ASGs/instance groups of the cluster) and no CloudInstance member matches options.InstanceID. The instance ID given on the command line does not correspond to any instance currently registered in the cluster's cloud groups.

Source

Thrown at cmd/kops/delete_instance.go:222

	var instanceGroups []*kopsapi.InstanceGroup
	for i := range list.Items {
		instanceGroups = append(instanceGroups, &list.Items[i])
	}

	cloud, err := cloudup.BuildCloud(cluster)
	if err != nil {
		return err
	}

	groups, err := cloud.GetCloudGroups(cluster, instanceGroups, false, nodes)
	if err != nil {
		return err
	}

	cloudMember := findDeletionNode(groups, options)

	if cloudMember == nil {
		return fmt.Errorf("could not find instance %v", options.InstanceID)
	}

	if options.CloudOnly {
		fmt.Fprintf(out, "Instance %v found for deletion\n", cloudMember.ID)
	} else {
		if cloudMember.Node != nil {
			fmt.Fprintf(out, "Instance %v (%v) found for deletion\n", cloudMember.ID, cloudMember.Node.Name)
		} else {
			fmt.Fprintf(os.Stderr, "Instance is not a member of the cluster\n")
			fmt.Fprintf(os.Stderr, "Use --cloudonly to do a deletion without confirming progress with the k8s API\n\n")
			return fmt.Errorf("error finding node name for instance: %v", cloudMember.ID)
		}
	}

	if !options.Yes {
		fmt.Fprintf(out, "\nMust specify --yes to delete instance\n")
		return nil
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. List current instances/nodes with `kops get instances` (or cloud console / `kubectl get nodes`) and confirm the exact instance ID.
  2. Verify you targeted the right cluster: add `--name <cluster>` and check KOPS_STATE_STORE points at the correct state store.
  3. If the instance is already gone, nothing to delete — verify with the cloud provider CLI (e.g. `aws ec2 describe-instances --instance-ids ...`).
  4. If you have only the node name, drop --cloudonly so deleteNodeMatch can also compare cloudMember.Node.Name.
  5. Re-run `kops update cluster` / refresh cloud groups if the instance group spec is stale.

Example fix

// before
kops delete instance --name mycluster.example.com i-0123xyz
// error: could not find instance i-0123xyz
// after
kops get instances --name mycluster.example.com   # find correct ID
kops delete instance --name mycluster.example.com i-0abc123def456 --yes
Defensive patterns

Strategy: validation

Validate before calling

// before running the command, confirm the instance exists in this cluster's groups:
clientSet, _ := f.KopsClient()
cluster, _ := GetCluster(ctx, f, options.ClusterName)
igs, _ := clientSet.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})
if len(igs.Items) == 0 {
    return fmt.Errorf("no instance groups for cluster %q; check --name and KOPS_STATE_STORE", options.ClusterName)
}
// verify the ID with the cloud CLI, e.g.:
// aws ec2 describe-instances --instance-ids i-0abc123 --filters Name=tag:kubernetes.io/cluster/<cluster>,Values=owned

Try / catch

cloudMember := findDeletionNode(groups, options)
if cloudMember == nil {
    return fmt.Errorf("could not find instance %q in cluster %q; run 'kops get instances' to list valid IDs", options.InstanceID, options.ClusterName)
}

Prevention

When it happens

Trigger: `kops delete instance <cluster> --instance-id i-0abc123...` (or a node name, when not --cloudonly) where the ID matches neither a cloudMember.ID nor — in API mode — any Node's name, i.e. findDeletionNode returns nil.

Common situations: Typo or truncated instance ID; instance was already terminated; querying the wrong cluster (--name) or wrong cloud provider account/region (KOPS_STATE_STORE/cloud config); passing a node name while using --cloudonly (node-name matching is disabled in cloud-only mode); autoscaler already replaced the instance so the ID no longer exists in any group.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/ca8c1e8f32b80884. Report an issue: GitHub.