Actually both.
On the civilian side of the military, there are "career" SESs, and there are "appointed" SESs. (SES - Senior Executive Service, the civilian equivalent of generals/admirals.) The latter are directly appointed by the administration. The former isn't quite as political, but it is definitely political. As for the generals/admirals, I'm talking more towards the 4-star guys/gals. Those are the ones that get the most "scrutiny" by the administration. The administration gets "their guys" into the big jobs. It isn't a "you're out, our guys are in" kind of thing like appointing the secretaries, but when a job comes up, you know the administration's guys are getting slotted into the job. If there is a general that constantly "locks horns" with the administration, it's not uncommon to see them being asked to resign, and the replacement will be someone more willing to work with the administration (even at the expense of the troops).
Don't be too surprised to find if the administration thinks a certain general/admiral may become too popular with the American public, they may dig until they can find a way to convict that person of a felony. That's a recent occurrence in the DoD's political game. I don't think it's ever happened before this president came into office.
Just look at the Navy (and probably other services too) spending a crap load of money doing "global warming" studies (among other "politically correct" projects/decisions).