With such a vast distance between the two countries, why would the countries even ally? Could there be any benefit for either country?
Here is an earlier post I did on the subject. Let me know if it doesn't answer all of your questions.
The Japanese had put a lot of effort into being recognized as a great power on par with the western powers. However, the army and militant radicals had been gathering power in Japan, to the point where they eventually got complete control of Japan. They changed Japan's goal from becoming a western style imperial power, to being an Asian based power that would liberate East Asia from the Europeans. Given that all colonies in East Asia were held by European enemies of Germany, so naturally both sides began to put 2 and 2 together. But an even more driving factor was the Soviet Union, whom both Germany and Japan considered to be a grave threat. They both signed the anti-Comintern pact (obligated them to help each other if either one was attack by a communist nation) which was the start of the German-Japanese alliance.
Now on Germany's side they initially did not have too much interest Asia, but they did maintain good relations with a number of Asian countries. The Germans actually supported the republic of china against the Japanese. German military advisors worked to modernize the military of the ROC and they maintained a good alliance. Germany also had good relations with Afghanistan, but that's a different topic. Anyways, this change when Von Ribbentrop became foreign minister and switched support to the Japanese. Von Ribbentrop was behind the decision to diplomatically recognize the Japanese puppet states of Manchuko and wang jingwei's china. Japan was seen as a better counterbalance to the soviets and it was hoped that they could be coerced into pulling the soviets into a two front war.
As for the racial aspect, Hitler actually respected the Asian races for their extensive history. He acknowledged that the Japanese had Aryan influences and were one of the "superior" races. Their hatred of Communism only boosted their status in the eyes of Hitler.
Sources:
The Second World War by John Keegan
Japan's imperial army: it's rise and fall by Edward Drea
History of japan 1541-1941 by L.M Cullen