If you really feel like you must swear allegiance to something, swear it to an ideal, not to a person or group. But if you feel like the armed forces need to swear allegiance to a person or group, why can't that be "the people" of the country they belong to? It's pretty much symbolic anyway.