rancher: [BUG] rancher machines are not removed from the cluster after actual worker nodes removed

Rancher Server Setup

  • Rancher version: 2.7.9, 2.8.0
  • Installation option (Docker install/Helm Chart): helm
    • If Helm Chart, Kubernetes Cluster and version (RKE1, RKE2, k3s, EKS, etc):
  • Proxy/Cert Details: none

Information about the Cluster

  • Kubernetes version: 1.27.8
  • Cluster Type (Local/Downstream): downstream custom rke2 on hosted on aws
    • If downstream, what type of cluster? (Custom/Imported or specify provider for Hosted/Infrastructure Provider):

User Information

  • What is the role of the user logged in? (Admin/Cluster Owner/Cluster Member/Project Owner/Project Member/Custom)
    • If custom, define the set of permissions:

Describe the bug After upgrade from 2.7.5 to 2.7.9 I’ve noticed that terminated worker nodes are still displayed on rancher UI with Nodenotfound status.

capi-controller-manager: is full of errors like:

E1204 17:41:44.435523       1 controller.go:329] "Reconciler error" err="no matching Node for Machine \"custom-fbdc7789f02e\" in namespace \"fleet-default\": cannot find node with matching ProviderID" controller="machine" controllerGroup="cluster.x-k8s.io" controllerKind="Machine" Machine="fleet-default/custom-fbdc7789f02e" namespace="fleet-default" name="custom-fbdc7789f02e" reconcileID=330124c5-1ffb-4f7d-a618-94a976c62106
E1204 17:41:44.585423       1 controller.go:329] "Reconciler error" err="no matching Node for Machine \"custom-be9d831e6358\" in namespace \"fleet-default\": cannot find node with matching ProviderID" controller="machine" controllerGroup="cluster.x-k8s.io" controllerKind="Machine" Machine="fleet-default/custom-be9d831e6358" namespace="fleet-default" name="custom-be9d831e6358" reconcileID=63186033-4f57-4524-85af-2123a88f3a04

machine resource mentioned in the error still exists: k -n fleet-default get machine | grep custom-be9d831e6358

custom-be9d831e6358   rancher-euc1-te-test01   ip-172-29-196-238.eu-central-1.compute.internal   aws:///eu-central-1a/i-0a82b430f14175488   Running       5h6m

but nodes.management.cattle.io resources for old workers are gone

Also in downstream rke2 cluster k get nodes doesn’t show these old nodes, so it is only affecting rancher.

To Reproduce

  • Terminate active running node

Result After node is terminated it is removed from the cluster but it is not removed from rancher and node still displayed on UI in Nodenotfound status.

Expected Result After node is terminated it is removed from the cluster and it is also removed from rancher.

Screenshots image

Additional context In slack other ppl mentioned that they have same issue starting from version 2.7.6 https://rancher-users.slack.com/archives/C3ASABBD1/p1701711546706849\

SURE-8277

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 43 (11 by maintainers)

Most upvoted comments

@snasovich I’m going to go ahead and re-open this issue.

While the original intention of removing this behavior was to better align with other providers upstream, I do believe there is merit for the various use-cases stated here (primarily auto scaling) that would benefit from a workflow that allows v1.Node objects to be deleted and have their corresponding CAPI machines cleaned up.

I believe we can re-add this behavior, but make it opt-in. Once enabled, the custom node controller in the CAPR infrastructure provider would reconcile/delete the corresponding CAPI machine objects if it sees a removal of the custom node. To those commenting on this issue that are affected by the change in behavior – would that work?

@snasovich I’m not following how this is by design? This basically means any use of autoscaling (cluster autoscaler, karpenter, manual scaling of underlying cloud resources) will leave lingering nodes within the cluster with no means for reconciliation, except for the temporary solutions posted above.

We have also noticed that upgrading cluster version, or applying any projects, roles, and mappings fail to go through since the cluster is not in an Active state when there is a NodeNotFound machine present.

What’s the appropriate method to trigger deleted through trigger/removal of the CAPI Machine object

@jdbaudean yeah, that is why I put that script into a cron job which is running every 15minutes to make sure that machine with stateNodeNotFound is removed as soon as it gets in to that state. In your case you might need to adjust interval.

Oh, I just realised that rke.cattle.io/delete-missing-custom-machines-after: '5s' annotation for the cluster.provisioning.cattle.io not for individual machine! Works as expected now with that annotation on a cluster. 🎉

Ticket #43686 - Test Results - ✅

Verified on Rancher v2.9-1c2b815c8dd66e141b21630904127adc8e03c3de-head:

Scenario Test Case Result
1. Provision custom rke2 cluster + delete a node; machine object expected to stay ✅
2. Provision custom k3s cluster + delete a node; machine object expected to stay ✅
3. Apply annotation to rke2 custom cluster + observe orphaned machine object terminate ✅
4. Apply annotation to k3s custom cluster + observe orphaned machine object terminate ✅
5. Take snapshot on custom rke2 cluster => upgrade k8s version => restore to snapshot ✅
6. Take snapshot on custom k3s cluster => upgrade k8s version => restore to snapshot ✅

Scenario 1 - ✅

  1. Fresh install of Rancher v2.9-head
  2. Provision a downstream RKE2 custom cluster w/ k8s 1.29
  3. Once active, take a snapshot
  4. Navigate to Cluster Explorer > Nodes and delete a worker node, then delete the associated instance on the cloud provider side
  5. Verified - issue is reproduced; NodeNotFound status is seen on the machine of the terminated node via Cluster Management > Machines; as expected

Scenario 2 - ✅

  1. Fresh install of Rancher v2.9-head
  2. Provision a downstream K3s custom cluster w/ k8s 1.29
  3. Once active, take a snapshot
  4. Navigate to Cluster Explorer > Nodes and delete a worker node, then delete the associated instance on the cloud provider side
  5. Verified - issue is reproduced; NodeNotFound status is seen on the machine of the terminated node via Cluster Management > Machines; as expected

Scenario 3 - ✅

  1. Utilizing the cluster from Scenario 1, Edit YAML, and apply the following annotation:
rke.cattle.io/delete-missing-custom-machines-after: '5s'
  1. Observe orphaned machine objects terminate
  2. Verified - cluster active and accurately reflects 1:1 ratio of nodes to machines; as expected

Scenario 4 - ✅

  1. Utilizing the cluster from Scenario 2, Edit YAML, and apply the following annotation:
rke.cattle.io/delete-missing-custom-machines-after: '5s'
  1. Observe orphaned machine objects terminate
  2. Verified - cluster active and accurately reflects 1:1 ratio of nodes to machines; as expected

Scenario 5 - ✅

  1. Fresh install of Rancher v2.9-head
  2. Provision a downstream RKE2 custom cluster w/ k8s 1.29
  3. Once active, take a snapshot
  4. Delete a node and observe associated machine object with NodeNotFound status
  5. Edit YAML and apply annotation, then upgrade k8s version to 1.30
  6. Once cluster is upgraded and active, restore to snapshot
  7. Verified - cluster successfully restores to snapshot, and is k8s 1.29 again
  8. Once more, upgrade k8s version to 1.30
  9. Verified - cluster successfully upgrades back to k8s 1.30; as expected

Scenario 6 - ✅

  1. Fresh install of Rancher v2.9-head
  2. Provision a downstream K3s custom cluster w/ k8s 1.29
  3. Once active, take a snapshot
  4. Delete a node and observe associated machine object with NodeNotFound status
  5. Edit YAML and apply annotation, then upgrade k8s version to 1.30
  6. Once cluster is upgraded and active, restore to snapshot
  7. Verified - cluster successfully restores to snapshot, and is k8s 1.29 again
  8. Once more, upgrade k8s version to 1.30
  9. Verified - cluster successfully upgrades back to k8s 1.30; as expected

@jdbaudean , my bad - missed that part - thank you for pointing me to it.

@snasovich We have noticed that leaving these abandoned machines in NodeNotFound status on large clusters with dynamic leads to the state where there are hundreds of abandoned machines and even rancher UI is struggling with loading cluster management view. This brakes custom node pools support.

@snasovich So far this happens when I delete a node from the cluster via the Rancher UI, delete a node using kubectl delete node <node-name>, and when the cluster-autoscaler removes nodes. That is by design?

As I also mentioned, if I try to go into cluster management and clean up the Nodenotfound nodes myself, Rancher will remove any node with the same Node name.

@okgolove That is exactly what I did, and put that into a CronJob but still looking forward for proper fix 😕

@Oats87 I’ve tried deleting the machines from both Cluster Management, and via the local cluster in the Rancher UI under Machines. That works, however if there is another node with the same node name Rancher will drain and cordon the node that actually does exist. We do a lot of autoscaling so an ec2 instance launched today might have the same IP (and Node name) as an instance that was previously killed and removed from the cluster by the CA days or weeks ago. For example

State                   Name                    Node
Nodenotfound   custom-f9d9d....   ip-10.114.30.227.ec2.internal
Running             custom-b5264....   ip-10.114.30.227.ec2.internal

If I delete the first node from Cluster Management it does delete the node that no longer exists, but it also drains, cordons, and deletes the second node which has active workloads.

To clarify, when using provisioningv2, cluster-api is the component responsible for performing the drain and cordon of your node. It’s definitely not ideal that you’re ending up in a situation where you have multiple machines that reference the same node – ideally cluster-api would refer to the node using the uid of the v1/Node object which would prevent that situation; however, it does not seem that it does that based on the behavior you’ve described. I’ll need to do some digging into determining a workaround for that specific situation.

I’m seeing this exact same behavior in 2.7.9. This happens every time the cluster-autoscaler removes a node, I assumed it was an issue with the cluster-autoscaler or my aws-cloud-provider config.

Unfortunately the slack link referenced above is older than 90 days, so historical context within that thread is lost.

I can confirm that this is still a problem with v2.8.2 of rancher on a clean install, which is using v1.4.4 of the cluster-api controller. After a bit of investigation the problem why this is happening is because the .metadata.deletionTimestamp field is never set on the machine resource, this is preventing the cluster-api controller from reconciling the deletion of machine resources.

Relevant code can be seen here: https://github.com/kubernetes-sigs/cluster-api/blob/00dbf7b9f6322d7ebd06ae2efa703b23354dd37d/internal/controllers/machine/machine_controller.go#L209-L219

I have checked the historic and future code of the cluster-api controller and this logic hasn’t changed on their side. Perhaps @Oats87 you might have some insight as to where this was previously happening within the rancher code base, and or where we should be hoping to introduce the necessary changes to correctly set the deletion timestamp.

This can easily be reproduced, by simply watching the cattle-provisioning-capi-system pod logs then deleting a machine resource that had previously failed to reconcile.

@okgolove I was trying to upgrade from 2.7.5 to 2.8.0 but I think this regression was introduced in 2.7.6