Wikipedia says, the president is the commander-in-chief, if I understand correctly, he delegates to the secretary of defense, who commands the military.
This certainly sounds like there is nothing the military can (legally) do against the president. They basically have to obey him.
Is there a legal way for the military to disobey? Have there been any precedences of the military going against the president, apart from outright coup?
It depends if the president is a legitimate one or not