I don't see any of the comments discussing the reason I think they felt the need to do this, even though my opinion is not unique it does seem minority. It was only partially about NATO expansion into Ukraine, and not the defence side of that, it was more about EU membership, and it was even more about Ukrainian politics and society. Ukraine has slowly been moving from a corrupt Russian like state to more resemble an eastern European EU member. Long way to go but the direction was clear from 2014 when Russia first rumbled, and it has accelerated since.
With that in mind, Ukraine presents a clear threat to Putin's regime. The potential of Russians seeing the country next door, of similar people with shared heritage and lots of social cross over, transition to a less corrupt, more democratic, western influenced nation. And if Ukraine had managed to join the EU there would have been a flood of investment, which while bringing its own problems I'm sure, would have improved the lives of Ukrainians. A demonstration of "throw out your corrupt leaders and see what you can have".
So the war is to nullify that, and even if it did not pan out in the way Putin had hoped, it's still succeeded in pushing away that particular threat. Even if the west now gives proper support to Ukraine defence, and follows it up with a rebuild, the war has split Ukrainian and Russian social linkage.