Bismarck handled that masterfully.
He knew it’d take a war to get Austria out of German affairs, but he made a generous peace with them so that they’d be allies.
If only he’d done the same with France, and not taken Alsace-Lorraine!
And later, if Germany had not tried to compete with Britain over naval armaments, we might have avoided WW1.
There was simply no way to counter the alliance system arrayed against the new Germany; agreements/relations with Russia and Italy in particular came to naught when war approached...