The ability to inflict damage through physical violence is probably the oldest forms to assert power (over other people) and either you reject the concept of power (over other people) categorically (anarchism, pacifism) or if you open Pandora's box you find yourself in a position where it is somewhat ambiguous. In the sense that power allows you to do extraordinary things by coercing others to do them, while on the other hand the power of other people over you might mean that you can't even do ordinary things.
So there are generally two motivations to seek that kind of power, either to abuse it or to protect yourself and others from abuse. The first is reasonably acceptable in that while violence still isn't great, but it's hard to argue with impulse of the living to keep on living and to not be subjected to pain and discomfort by the hands of others. So you can make an argument in favor of protective violence and the preparation for that.
... and you can be fairly sure that if a bad faith actor is in need of a justification to erect an army and prepare for violence, they WILL also claim that argument whether it's true or not. So again not unreasonable, certainly not great.
Furthermore there's the problem that the existence of armed forces creates a game theoretical problem akin to the prisoners dilemma., in that it would be beneficial for every side if they cooperate and not have armed forces (non productive members of society, inherent risks of coups and power grabs, provide an incentive for others to strike first), but there's a stronger individual incentive not to be the person/country that cooperates and ends up being defenseless when the rest doesn't. Which has already brought us to the development of ever more deadlier super weapons that could annihilate our existence altogether, so yeah "rationality" with respect to risk avoidance in that regard is a rather risky business.
Also with very little exceptions organized armed forces are usually not ideally compatible with democracies. Sure you could organize them in militias (ad hoc citizen armies), but modern militaries usually go for the model of a standing army that is only reinforced with regular citizens in times of war. Which usually includes a top-down chain of command, a level of secrecy and an illegality to disobey orders. Which is pretty incompatible with most democratic principles and lends itself more to authoritarian thinking as it encourages to see individual soldiers as pawns in a chess game and relegates the role of the individual soldier to that of a tool in the hands of his/her superiors.
Now from what I know, the ethical principles dealing with the military are the just war theory and the moral equality of combatants. One assumes that there are just causes to go to war, such as self-defense, establishment of a just peace, humanitarian intervention and so on and the second assume that all combatants on all sides have the same moral status; Which makes the assumptions that all soldiers get told that they fight in a just war and that they don't commit war crimes which obviously breaks that illusions and would alert them to act upon that knowledge.
So in other words soldiers are considered to be free from responsibility for their actions as they ceased their agency to their superiors meaning their last action as moral agents was the choice of their employer and their trust in that person's judgment and character to only fight just wars.
Though that largely applies only to soldiers at war when there is a very high probability that either side is lying to it's soldiers one way or another and they lack the ability to confirm or reject the official narratives. In which case it's more or less a blind faith in one's one government/military high command.
Not sure though that this actually is the "real" moral point of view of the individual soldier or whether it's maybe even the opposite of that and being in combat gives them a sense of agency to change a dreadful situation that they would otherwise just have to suffer through hoping that powers outside of their control work in their favor, though explicitly using coercive means irrespective of their moral justification as part of what they consider is necessary. The argument that they protect their families usually only works in a very abstract sense, as their services primarily takes them away from their families and thus makes that quest impossible.
And lastly as that is about joining, you could also have coercive measures to force people to join such an institution, like conscription or the lack of social security measures so that the military becomes a last resort option of a stable income and social mobility actively encouraging the individual soldier to disregard these ethical questions and just consider it as "a job". Regardless of the fact that this job has many serious ethical consequences.