Given a metric space $X$ and $K \subseteq X$ compact, where $K \subseteq U$ such that $U$ is open. I am trying to show that there exists some $\epsilon > 0: \bigcup_{x \in K} B(x,\epsilon) \subseteq U$.
Since $K$ is compact any open cover $\{U_i\}_{i \in I}$ of $K$ admits a finite subcover. $U$ is an open cover of $K$ and given $\epsilon > 0, \bigcup_{x \in K} B(x,\epsilon)$ is an open cover as well. Furthermore, since $U$ is open, there is some $r > 0$ such that $B(x,r) \subseteq U$. I'd like to conclude that $\bigcup_{x \in K} B(x,r) \subseteq U$ but I don't think this is true. Any suggestions?
Using compactness, produce $x_1, \ldots,x_n, \epsilon_1, \ldots, \epsilon_n$ such that $K \subseteq B(x_1, \epsilon_1) \cup \ldots \cup B(x_n, \epsilon_n) \subseteq U$. If $n = 0$, then $K = \emptyset$, and the problem is trivial. We now consider the case $n > 0$.
Define the function $g(x) = \sup\limits_{1 \leq j \leq n} (\epsilon_j - d(x, x_j))$. Note that $g : K \to (0, \infty)$ is continuous. Thus, its image is compact. Then take some $\epsilon > 0$ such that $g(K) \subseteq (\epsilon, \infty)$. I claim $\bigcup\limits_{x \in K} B(x, \epsilon) \subseteq U$.
For consider some $x \in K$. Then $\epsilon < g(x)$. Thus, we can take some $j$ such that $\epsilon < \epsilon_j - d(x, x_j)$. Then we have $B(x, \epsilon) \subseteq B(x_j, \epsilon_j) \subseteq U$ by the triangle inequality.