It the simplest case, $\succeq$ is a total order -- so that for all $x,y \in K$, either $x \succeq y$ or $y \succeq x$ or both -- and the right condition is continuity of $\succeq$: for all $x \in K$, the sets $\{ y : y \succeq x\}$ and $\{y: x \succeq y\}$ are both closed. If $\succeq$ is a total order that is continuous and transitive, then a continuous function exists that represents it; this is usually called Debreu's Theorem, but there is another, older result called Rader's Theorem, that guarantees the weaker conditions of upper semi-continuity, which suffices for existence of a maximizer but not a minimizer.
If you only have a pre-order, there is a result called Levin's Theorem. If the graph of $\succeq$ is closed in $K \times K$ and $\succeq$ is acyclic, then a continuous function exists that represents $\succeq$, and the Weierstrass-type conclusion follows.
References on these topics would be Nachbin's "Order and Topology", Efe Ok's "Real Analysis with Economic Applications", Trout Rader's "Theory of Microeconomics". Levin's Theorem is hard to find (it was published in a Soviet math journal and reprinted in an AMS volume), but Ok et al have a recent paper called "A Comprehensive Approach to Revealed Preference" that has a proof of it in the appendix and other references. You might also like Border's "Fixed point theorems with applications to economics" that includes lots of content about when $\succeq$ have maximizers.