You serve your term of duty as an enlisted person, and you get discharged after your term of enlistment expires. Except that you actually don't. I served four years in the USAF, but was in the inactive reserve even after my term of enlistment was ended. I don't remember how many years that was, and it never restricted me from doing what I pleased after my discharge.
There were other restrictions, as well. I worked in an job that involved Top Secret materials, some of them SCI documents. When I was discharged, that did not free me from restrictions about that work. For 10 years after that, I had to notify the USAF if I traveled outside of the USA. I was barred from traveling to certain countries for an indefinite period of time. As far as I know, I still cannot go to those countries. I also cannot reveal some things about the work I did. Even though some of it has been declassified, not all of it has, and there's no clear boundary about that. So, I say nothing other than the things I was told at the time I could talk about. I just don't know what I can discuss and what I cannot. Nobody's watching me, of course, but there's always a risk.
For senior officers in the US military, the restrictions are even tighter. Really, you can't ever completely retire from the military if you are in that category. You can be relieved from duties when you retire, but you are always subject to being recalled to duty. So, that's what's going on with the issue in this thread. You take an oath when you join or are commissioned. You are never relieved of that oath. It remains part of your life.