This is quite a complex situation and there’s not really a single clear answer. Broadly speaking, there are 3 explanations that have been commonly offered for the current conflict. These reasons are not mutually exclusive but opinions differ on which of them is more important.
Reason 1) The Russian leadership views NATO as a threat.
NATO as an alliance was set up in opposition to the USSR back in 1949. After the breakup of the Soviet Union, reconciliation efforts between Russia and NATO were stillborn.
Although Russia did not join NATO, most of the former Soviet Bloc in Europe and several former Soviet Republics (the Baltic states), did join NATO. In 2007, NATO and Ukraine agreed that in principle, Ukraine could join NATO. Russian politicians have frequently pointed out that the expansion of NATO into former USSR/Warsaw Pact countries goes against promises that US leaders made to Gorbachev in 1990, during negotiations over German reunification. What really happened is more confused, but declassified archival documents show that Gorbachev was given concrete ‘assurances’ – here’s a good article on the NATO expansion controversy.
From the Russian perspective, Ukraine joining NATO would mean that Russia’s entire Western border (minus Belarus) in controlled by an alliance that Russia sees as her main external enemy. Thus, the threat of invading Ukraine is meant to force NATO to come to the negotiating table and guarantee that Ukraine will not join NATO. It’s highly unlikely that NATO will accept this, hence the current conflict.
Reason 2) Putin using nationalism for domestic support.
This is another common explanation. It’s widely accepted that ‘rallying around the flag’ and directing anger towards a common enemy is an effective tool for politicians to stay in power. Indeed, after the annexation of Crimea in 2014, Russia saw a massive resurgence in patriotic-nationalist sentiment and Putin’s approval ratings jumped to over 80%.
Thus, the Russian government under Putin uses the threat of NATO as a means of garnering domestic support by presenting himself as the defender of Russian sovereignty and status in the world after the perceived humiliation of the 1990s, when Russia was weak.
It has thus been argued that it is in Putin’s interest to keep the conflict with NATO over Ukraine going in order to keep his popularity in Russia.
Reason 3) Historical ties between Russia and Ukraine and Russian nationalism.
Ukraine and Russia have a very close history: Ukraine was a republic of the USSR and before that was part of the Russian Empire. Both countries also have an extensive shared cultural heritage (of course, with many differences as well).
Russian politicians, including Putin, have frequently used these historical ties and shared cultural heritage to argue that Russians and Ukrainians are ‘one people’ and thus that Ukraine should be aligned with Russia instead of the West.
Naturally, Ukrainians largely resent this. They see such arguments as erasing and diminishing Ukraine’s national identity by relegating it to ‘Little Russia’ and as a justification for Russian imperialism.