Urysohn's lemma with Lipschitz functions In a complete and separable metric space $(X,\mathrm{d})$, let an open set $U$ and a closed set $K\subset U$ be given. Is it possible to find a Lipschitz function $f$ such that $f|_K=1$ and $f|_{X\setminus U}=0\,$?
By Urysohn's Lemma we know that a complete metric space is normal (i.e. the closed sets are separable by neighbourhoods), and as such, the closed sets are separable by continuous functions. So a continuous function exists but I don't see anything more than that.
 A: In general, this can not be done.
To see this, note that this would imply that for $x \in K$ and $y \in X \setminus U$, we have
$$
1 = |f(x) - f(y)| \leq L \cdot d(x,y),
$$
where $L$ is the Lipschitz-constant of $f$.
Hence $d(x,y) \geq 1/L$ for all $x \in K, y \in X\setminus U$, i.e. the distance $d(K,X\setminus U) \geq 1/L > 0$ is strictly positive. But there are examples of such sets with $d(K, X\setminus U) = 0$ (even in $\Bbb{R}^2$).
Now, assume that $\varepsilon := d(K,X \setminus U) > 0$. Set
$$
f(x) := \min\{1 , d(x, X\setminus U)/\varepsilon\}.
$$
It is an easy exercise to show that $f$ is Lipschitz with the desired properties.
A: If $d(K,X\backslash U) = 0$ then no uniformly continuous function $1$ on $K$ and$0$ on $X \backslash U$ exists. So you might want some compactness condition.
If $X$ is a  subset of some $\mathbb{R}^n$ with the induced metric or a  manifold with  a Riemannian metric then one can find smooth functions $f$ satisfying the conditions. Smooth functions are locally Lipschitz.
For any metric space $X$ it's easy to write an explicit $f$:
$$f(x) = \frac{d (x, X \backslash U)}{ d(x,K) + d(x,X \backslash U)}$$
Assume that $d(K, X\backslash U) = \delta >0$. Now use the fact that the functions $x \mapsto  d(x,K)$, $x \mapsto d(x,X \backslash U)$ are Lipschitz with constant $1$ and the fact that the function $(a,b) \mapsto \frac{a}{a+b}$ is Lipschitz on $\{ (a,b) \ | a,b \ge 0\  \textrm{and } a+ b \ge \delta \}$ to conclude that $f$ is Lipschitz. The Lipschitz constant turns out to be $1/\delta$, the best we can get. 
More general, on any subset $A$ on which $d(x,K) + d(x,X \backslash U)$ is bounded below by $\eta>0$ the restriction of $f$ to $A$ is Lipschitz with constant $\eta$.
A: In the answer given by @orangeskid it is possible to use a much simpler function as
$$
f_\varepsilon(x) = \max\{1-\varepsilon^{-1}d(x,K);0 \}
$$
with $0<\varepsilon\leq \delta$
