Technically the military in Canada swear allegiance to the monarchy in Canada.
The monarchy of Canada is legally completely distinct from the one in the UK. Or Australia. Or New Zealand. Or any other of HRHs realms and dominions.
It’s just that they all share the same monarch and the rules of succession.
It’s actually theoretically possible for Charles to abdicate the throne in the UK but still remain the King of Canada. Which would be utterly ridiculous and it’s not going to happen, but theoretically it could.