On what kind of condition of a compact set $K$ in the plane, $C(K)$ has a generator?
A partial answer: if $K$ has empty interior and ${\mathbb C}\setminus K$ is connceted then Lavrentiev's theorem tells us that $P(K)=C(K)$. (See e.g. Gamelin's book on uniform algebras.) In such cases the function $z\mapsto z$ is a generator of $C(K)$ in the sense of your question.
In view of Nik Weaver's observation in the comments I am inclined to guess that this sufficient condition on K is also necessary but I currently don't have time to think about this further.
Note, in view of glenlair's answer and the comment on MSE, that there are obvious examples of such $K$ which are not homeomorphic to subsets of the real line. For instance, take three copies of $[0,1]$ glued together at $\{1\}$ in a tripod shape. This is a compact connected space with the property that removing a certain point leaves three connected components. But compact connected subsets of the real line are closed intervals (or singleton sets) and in those cases removing a point can leave at most two connected components.
I believe Yemon's conjecture is correct: $C(K)$ has a generator in the sense of the question if and only if $K$ has empty interior and $\mathbb{C}\setminus K$ is connected. As he points out, the reverse direction follows from Lavrentiev's theorem. For the forward direction, if $K$ has nonempty interior then Mr. Li has already pointed out that we know $C(K)$ has no generator: this easily follows from David Ullrich's answer to a previous question which says that $C(S^1)$ has no generator, and the fact that $K$ contains a homeomorphic copy of $S^1$.
Now suppose $\mathbb{C}\setminus K$ is disconnected and assume $C(K)$ has a generator $f$. I claim that $K$ has a component $K_0$ such that $\mathbb{C}\setminus K_0$ is disconnected. Granting the claim, $C(K_0)$ also has a generator $f$, namely the restriction to $K_0$ of any generator of $C(K)$. It is obvious that $f$ must be 1-1 on $K_0$, so by a standard fact it is a homeomorphism between $K_0$ and $f(K_0)$. According to the answer to this question, $\mathbb{C}\setminus f(K_0)$ is also disconnected. Then $f(K_0)$ contains the boundary of a bounded open set, namely any bounded component of its complement. But now David Ullrich's argument for $S^1$ carries over verbatim to this setting to yield a contradiction. End of proof, modulo the claim.
To verify the claim, let $U$ be a bounded component of $\mathbb{C}\setminus K$, let $V$ be the unbounded component of $\mathbb{C}\setminus\overline{U}$, and let $K_0 = \partial V$.