Where was NATO expanding to at the time exactly? Ukraine first applied for NATO membership in 2008, so is this some kind of delayed reaction or something?
That wasn't what caused the war, NATO has only ever been a defensive alliance within Europe. What caused the problem was Ukrainians wanting to join the EU, which would have taken trade away from Russia, Putin couldn't accept that and went behind their back to head it off in 2013, the result was the Maidan revolution. His own idiotic fault. He then responded by annexing Crimea and warring in the Donbass, which led to Ukraine wanting to join NATO even more.
A cascade of errors, all made by Putin. Putin thinks all adjacent countries belong to him.
This issue is completely about the EU. Don't let Putin's forked tongue comments about him not being bothered about Ukraine joining the EU fool you, he already knew he'd made a deal with Yanukovych to join the EEU when he made that comment. It's always about economics. It's not like the US and EU had even been seeing eye-to-eye. European security was ran by Europe and not the US, that's why the poor dumb barstards made the mistake of becoming reliant of Russian oil.