How did Canada become an independent country?

It happened gradually over time. In 1867 Canada did officially become a country but under the British Crown it still had colonial status. Different Prime Ministers did small things here and there to further Canada's independence, for example when Sir Wilfrid Laurier (PM from 1896-1911 I think) created his own Navy for Canada instead of sharing Great Britain's.

The two biggest strides though were probably first of all when Borden insisted that Canada have its own seat for the signing of the Treaty of Versailles (right after the world war one), which meant for the first time that Canada's international affairs were separate from Great Britain's, and of course when Trudeau brought the constitution home in 1982 which officially allowed Canada to make amendments to its own constitution instead of having to ask Great Britain to amend it for us, and was also the last step in becoming a completely independent nation.