If $K$ is compact, totallyextremally disconnected and infinite, then for every compact subset $D\subseteq\mathbf{C}$ there exists $a\in C(K)$ with spectrum $\sigma(a)=D$.
[edit: Previously, $K$ was only assumed totally disconnected. As pointed out by Eric Wofsey, this is not enough.]
Proof: Choose a sequence $(x_k)_k$ in $D$ such that $\{x_k:k\geq 1\}$ is dense in $D$. Using that $K$ is totally disconnected and infinite, choose pairwise disjoint, closed and open subsets $A_k\subseteq K$ with $K=\bigcup_{k=1}^\infty A_k$. Let $a\colon K\to\mathbf{C}$ be the function that takes value $x_k$ on $A_k$, for each $k$. One checks that $a$ belongs to $C(K)$.
The spectrum of $a$ contains each $x_k$. Since the spectrum is closed, it contains $D$. One checks that the spectrum of $a$ is also contained in $D$. It follows that $\sigma(a)=D$.