Don't really want to defend Putin, but consider that Russia would at the very least lose the naval base in Crimea, if the Ukraine entered NATO. Also, in 2013, the EU put an ultimatum to Ukraine to choose between the free trade with EU or free trade with Russia.
Perhaps Putin's action isn't as irrational as it seems?