My take is that its complex. It's clearly not ALL about NATO membership, because as others have pointed out, he has NATO members on his border already. But equally the NATO piece should not be dismissed. Putin himself has said that he feared that were Ukraine to join NATO and subsequently try to take back Crimea, then he would not be able to protect Crimea without starting WW3. A strangely rational argument for a supposed madman.
But I am sure
@domalino is also right about Putin's genuine belief that Ukraine "belongs" in Russia. It's not a coincidence that he invaded Ukraine and not e.g. Finland.