Let $\mu(X)=1$, $0 \leq f \leq k$, and $m=\int_X f d\mu$. Show $\int_X |f-m|^2 d\mu \leq \frac{k^2}{4}$.
Hint: write the integrand as $\left((f-\frac{k}{2}) - (m - \frac{k}{2})\right)^2$. By expanding you should be able to show that $$\int_X (f-m)^2\,d\mu = \int \left(f-\frac{k}{2}\right)^2\,d\mu - \left(m-\frac{k}{2}\right)^2 \le \int \left(f-\frac{k}{2}\right)^2\,d\mu.$$ But we have $|f - \frac{k}{2}| \le \frac{k}{2}$...