I know that Nicholas II and Wilhelm II had a really good relationship but they were on opposite sides in WWI. Why?
Russia and Germany was originally allied under the League of Three Emperors alliance from 1873 to 1887. After Russia gains increased influence in the Balkans after their victory in the Russo-Turkish war, Austria-Hungary becomes enraged to see that their main rival for influence in the Balkans gained even more power. Bismarck called a congress to sort out the problem, and ended up giving Bosnia to Austria-Hungary as "compensation". Russia is not satisfied with the outcome and blaims Germany for the part they took in deciding the outcome. This causes Germany and Austria-Hungary to form the Dual Alliance which promised aid if either was attacked by Russia.
A renewal of the League of Three emperors alliance took place in 1881 but once again the alliance broke down because of conflict of interest in the Balkans. Bismarck who saw the absolute need to be on good relations with Russia to prevent a possible war on two fronts negotiated a Reinsurance treaty with Russia in which both countries promised to remain neutral should the other be involved in a war with another country. In 1890 Bismarck was sacked by Wilhelm II, and the new chancellor saw no real profit in keeping the treaty ongoing despite Russian requests to renew it. Wilhelm II was also convinced that his good personal relations with the Russian tsar was enough to maintain good diplomatic relations, but their relations became even more strained because of increased Russian influence in the Balkans. France seized the opportunity and in 1892 Russia and France became allies.
After Nicholas II gains the throne in 1894 despite his good relations with Wilhelm decides to maintain the alliance, and even though he was positive to an alliance with Germany at a later point turns down the proposal because of large opposition by his advisers. The Franco-Russian alliance was directed at Germany and was a crucial step towards WW1.
PS: Will post sources if asked but they are not in english.
Russia's support for Serbia put Nicholas and Wilhelm at opposing sides, as it arrayed the Russians against Austria-Hungary (the only real ally Germany had). When the Russians mobilized, Nicholas informed Wilhelm that he had no intention of going to war if the Germans could get the Austrians to step down from the brink. Instead, the Germans seized the opportunity to portray Russia as the aggressor, a pre-condition for any Germany act of war since Dec. 1912, and then move against the French.