NATO was a collective security response by liberal capitalist democracies faced with the possibility of an opportunistic Soviet Union expanding beyond the spheres of influence marked out at Yalta.
Its central premise was that liberal democracy was threatened (from within as much as from without) by communism. Its legitimacy was defined by its strategy of containment rather than offence, by nuclear deterrence and (unlike many other anti-communist treaty arrangements) by defence of democracy. All these sources of legitimacy are now questionable and are being questioned.
That which had to be contained appeared to disappear with the failure of the coup against Gorbachev in 1991 and the dissolution of the Soviet Union. A power vacuum appeared. The temptation to fill it through expansionary means was too good for 'hawks' to miss. The patience of Russia became exhausted after a series of humiliations. A red line appeared to be drawn in the Georgian-Russian War of 2008. Moscow moved forward to defend Russians in Ukraine. NATO now finds itself on the defensive again - on behalf of Balts who do not always treat their minorities well.
What happened between 1991 and 2008 was that NATO, in a series of almost accidental responses to events that were increasingly out of control at the margins of the developed world (the Balkans, the Middle East and Africa), raised the ante by moving from a defensive posture to an interventionist one, apparently for humanitarian reasons but with the widespread suspicion that it also had a values and capital agenda. This triggered resentments. The unravelling of the classic UN position of border inviolability was resisted by Russia until it decided it could play the same game.
The problem for NATO was ostensibly only a problem with Russia and Russian ideology (no longer communist but neo-nationalist) but it became a problem with its own electorates. Defence of democracy against tyranny became associated between the fall of the Soviet Union and the post-2008 age of populism with an ideological liberalism against which electorates are now themselves rebelling, with negligence and incompetence (leading to cruelty and migration) in its interventions and, in some quarters, with holding on to a deterrence model that required a war crime to effect.
A key note member, Turkey, has declared a State of Emergency that drags NATO back into the age of the Greek Colonels, fine but not after decades of taking the high moral ground. Ukraine is technically not defensible by NATO but it has behaved as if it should be involved. West Europeans know that this is a corrupt oligarchy in which radical nationalists have a significant voice. Trident may have passed Parliament easily but only under conditions where the bipartisan majority required the support of a party whose own members are in rebellion against it - and on this issue.
Every given paradigm in international relations is showing cracks - from Trump's own neo-nationalist vision of the US to the vulnerabilities of the European Union. NATO is no exception. Its legitimacy is not directly questioned by the vast majority of those in countries that belong to it but questions are being raised which may start to chip away and fragment the prevailing consensus that NATO is a force for peace rather than a destabilising influence on its own account. It should learn from Brexit - redefine itself on terms electorates can understand before the existential crisis happens.