That's a very generic question and maybe I'm not the right person to answer but I think sometimes you just can't. Here I'll show you a game I managed to draw by stalemate.
Avoiding stalemate

You have to advance as further as you can with the king in the pawn's file, trying to influence the last three squares, and only then advance the pawn. As for PedroMalves's example those positions are always drawn by stalemate if the king manages to secure the corner square.
Yes, that's absolutely right

Yeah. Remember: Black's king must be in front of the pawn to win.
Correct. Note that 1.Kc1 loses after Ke7.
This puzzle's connection to this topic is that it illustrates one of the lesser-known rules about getting a draw. If White has a king and pawn and Black just a pawn, Black will draw, if possible, by taking the vertical opposition. If White's king is one rank ahead of the pawn, the direct opposition is required. If White's king is on the same rank as the pawn, the distant opposition will suffice. If White's king is two ranks ahead of the pawn, Black loses.
How can I avoid a stalemate in a situation where I have just a pawn and a king and my opponent having just a king?