I'm trying to calculate the Electric Field over a thick spherical sphere with charge density $\rho = \frac{k}{r^2}$ for $a < r < b$, where $a$ is the radius of the inner surface and $b$ the radius of the outer surface.
From Gauss's Law I've got it to be $\vec{E} = \frac{k}{\epsilon_0}\frac{r-a}{r^2}$. But also tried to integrate the charge over the surface and I was hoping to get the same result but didn't. My attempt was, in spherical coordinates:
$$ \begin{equation} \begin{aligned} \vec{E} &= \frac{1}{4 \pi \epsilon_0}\int_a^r \int_0^\pi \int_0^{2\pi} \frac{\rho r^2 \sin \phi}{r^2} d\theta d\phi dr \vec{e_r}\\ &= \frac{1}{4 \pi \epsilon_0}\int_a^r \int_0^\pi \int_0^{2\pi} \frac{k \sin \phi}{r^2} d\theta d\phi dr \vec{e_r}\\ \\ &= -\frac{k}{\epsilon_0}(\frac{1}{r} - \frac{1}{a})\\ &= \frac{k}{\epsilon}\frac{r-a}{ra}\vec{e_r} \end{aligned} \end{equation} $$
Which are not the same. But they should be! I know that my Gauss method gave me the right expression, but I can't figure out why the integral method didn't.
The issue is an inconsistency in the way you use the symbol $r$.
Coulomb's law says that the electric field at a point $\mathbf r$ arising from a charge at a point $\mathbf r'$ is inversely proportional to $|\mathbf r - \mathbf r'|^2$, and is directed along the vector $\mathbf r - \mathbf r'$. The $r^2$ that appears in your definition of the charge density refers to the distance from the origin of your coordinate system to where the charge is located.
The integral you should be solving therefore looks as follows:
$$ \mathbf{E}(\mathbf r) = \int_a^R\int_0^{\pi}\int_0^{2\pi} \frac{\rho(r') r'^2\sin \phi}{|\mathbf{r} - \mathbf{r}'|^2} \widehat{\mathbf{r} - \mathbf{r}'}\mathrm{d}\theta\,\mathrm{d}\phi\, \mathrm{d}r', $$
and that does indeed give the expected result, but the calculation is a bit of a slog.