I think the way to do is to not make it illegal to own a gun, but, if you want to buy or sell, or to mass produce, then you need a license (but it should not be banned entirely), and you also need mandatory training (but only once, not every month or year) to purchase a gun.
Also, I think that it should be preferred (but not mandatory) to use weapons and defenses other than a gun. You can fight by hand, arrows, sword, staff, stones, gardening tools, sharpening the edges of DVDs and throwing them, etc (or, if you are a pacifist, then you do not have to fight at all). So, having a gun should be discouraged, but it should not actually prevent you to have one if you wish. (If the weapon emits excessive amounts of ionizing radiation, then it would be banned, though.)
And, military service should never be required. (Requiring training to purchase a gun is good, but it should be only once; otherwise the law becomes too obstructive.)
Guns should not be mandatory either; some people don't like guns. (Apparently in one place, it is mandatory to own a gun unless you don't like guns, or cannot afford it, or any of a number of other exceptions. So, such law is not obstructive, and if it is shown to help, then it should be kept, but if it makes it worse, then it should be discarded.)
I live in Canada, and I think the law is that when transporting guns they must be unloaded, and that seem good to me (although the law as implementation may be a bit too strict), and once the police department said that anyone who has a gun but doesn't want it can voluntarily give to them, and I think that is OK too.
Threats requiring self-defense are rarely specified in advance.
To your larger point, though, I don't think I've ever met a municipality that, as an incorporated entity, had the spine to stand up to anything. You would be creating a locally-centralized stockpile that could easily fall into the hands of the feds or of the first angry mob that comes along and seizes it, whether by bending the town council or by storming the armory. Do you want me to simply hope that the mob will be on my side?
A revolution is a matter of public opinion even more than it is a matter of martial might. The day that the feds start nuking their own people is a day by which they have already lost the war.
Anyway, the argument here is as much about the government controlling the people as it is about the people controlling the government. If the US government turned against its own people militarily, the only way you could recover is if you could regain control of the military and turn it back against the government or if you could somehow get a more powerful military to overthrow it. A revolution from within can only succeed if it controls the actual military.
However.
I’ve recently been wondering how we might maintain this bulwark while eliminating individual firearm possession, except in extraordinary and limited cases.
I wonder if incorporating the 2nd at the municipal level rather than at the individual level might be the answer.
Individuals could “own” guns, but would be required to store them at their local police station, and could check them out on a time-limited basis for recreational purposes, or for self-defense against a specified threat (using a similar process as getting a restraining order). Periodic psych evaluations would also be required to maintain check-out privileges.
And, if the federal government goes berserk, there still exists a massive arsenal outside of their immediate control. Even 5-10% of municipalities refusing to go along with federal orders would be enough to sustain an armed resistance that would make Afghanistan look like a tea party.