From a German POV:
Shortly after the opening to Japan in 1853, the Norddeutsche Bund, a group of several Northern German countries (including Luxembourg) that was the pre-organisation of the late German Empire tried to make friendship treaties with Japan like other Western states. Japan said no because the confederation was quite weak. They made a treaty with Prussia though and started to have a scientific exchange with it.
Seeing the Prussia and the German states fight in several wars and at the end becoming united made them think of the new Germany Empire as a militarily strong country and so, when they went to Europe and America to learn, they also went to Berlin. The university system, school system, a lot of teaching books for medicine and other sciences, the constitution in the year 1889 and, of course, the military was inspired by the Prusso-German system and advised by German-Jewish advisors.
In WW1, Germany and Japan fought on different sides because Germany tried to gain power in China. There were German war prisoners in Japan, but they were treated relatively well, which lead to some of them staying in Japan even after they were officially released (because in Germany, there was a financial crisis and a very political insecure situation at that time.)
Then WW2 came and they became friends again, and since then, Germany and Japan were more-or-less friends. A lot of German cities have Japanese partner cities, and since both countries had to build up their country, society, and economy again, there was a lot of economical exchange in the following decades. :)
I think it also has something to do with the mentality of the countries; both have a strong working ethos, a relatively strict social system that builds on politeness and certain aloofness. I suppose that these similarities paired with the exoticness of being Caucasian make the stereotypical German interesting and cool for the Japanese that write the manga. Not to forget that our language is just really badass and beautiful and awesome. ;)