Density of quantum states allowed For a 3D particle in a box, the density of states (or the number of allowed states with a wave vector whose magnitude lies between $k$ and $k + dk$ is) is given by: $$g(k) dk = \frac{V k^2 dk}{2 \pi^2}$$ where $k$ is the magnitude of $\vec{k} = k_x \hat{i} + k_y \hat{j} + k_z \hat{k}$ and $V$ is the volume of the box and they in turn are given by: $$k_x = \frac{n_x \pi}{L}$$ and similarly for $k_y$ and $k_z$ where $n_x$ is an integer.
Now, my doubt is that here we are finding the number of states whose wave vector lies in the range $k$ and $k + dk$, but as states above $k$ can take only certain values and is not a continuous variable? How is that possible?
 A: The first formula refers to quantization in the single coordinate/variable $k$, the Euclidean-norm $k=\sqrt{k_x^2+k_y^2+k_z^2}$. This also assumes that we have integrated the other two spherical-polar coordinates, $\theta$ and $\phi$. In a nutshell, we switch from the coordinates $\{k_x,k_y,k_z\}$ to $\{k,\theta,\phi\}$, and then integrate over $\{\theta,\phi\}$.
The second formula refers to the individual Euclidean components, $\{k_x,k_y,k_z\}$.
A: First, note that the quantization of $\vec k$ given by the OP arises from the boundary condition that the wave function vanishes at the walls of the box, while in Solid State Physics the most common one is the Born-von Karman (or periodic) boundary condition, which quantizes the $\vec k$ the following way
$$k_i=\frac{2\pi}{L}n_i\,\,\,,\,\,\,n_i\in\mathbb Z.\tag{1}$$
This quantization is only used to stablish the volume in $k-$space that a single allowed value of $\vec{k}$ occupies, which is $$\left(\frac{2\pi}{L}\right)^3.\tag{2}$$
Then, if we have a region of $k-$space of volume $\Omega\gg\left(\frac{2\pi}{L}\right)^3$, we can conclude that it contains
$$\frac{\Omega}{(2\pi/L)^3}=\frac{\Omega V}{8\pi^3}\tag{3}$$
allowed values of $\vec{k}$. Equivalently, this means that the number of allowed values per unit volume of the $k-$space is
$$\frac{V}{8\pi^3}.\tag{4}$$
Now, if we are interested in how many values of $\vec k$ lie on a differential volume $d^3\vec k$ of the $k-$space, we have to multiply $(4)$ by this differential volume, which can be expressed in spherical coordinates in the $k-$space
$$\frac{V}{8\pi^3}d^3\vec k=\frac{V}{8\pi^3}k^2\sin\theta\,d\theta \,d\phi\,dk.\tag{5}$$
If we are just interested in how many values of $\vec k$ have a magnitude between $k$ and $k+dk$, we can integrate ($5$) in the angles, wich gives a $4\pi$ factor, so the number of values of $\vec k$ satisfying $(1)$ whose magnitude is between $k$ and $k+dk$ is
$$\frac{V}{2\pi^2}k^2\, dk\equiv g(k) dk.$$
References

*

*Solid State Physics by Ashcroft and Mermin
A: Good Question. This is the same as asking, if charge is quantized, how can we consider things like a sheet of charge, or an infinite line charge, or a volume charge distribution that obeys-  $\nabla^2\phi=-\rho/\epsilon_o$, where the charge is supposedly continuous.
The answer to this problem is that in nature, most charge distributions you deal with are much much greater than $e$. So even if, by calculus you take an infinitesimal charge $dq$, even that small charge $dq$ can be as large as $1000e$ with almost no error at all. And you never go smaller than $dq$ do you? Thus it doesn't hurt to consider charge as continuous.
Now let us talk about statistical mechanics- the role of $e$ in the above problem is being played by the volume of the phase space unit cell- $\pi^3/V$ which is extremely low for a container large enough to allow weakly interacting particles. We know that-
$$k=\pi\sqrt{\dfrac{n_x^2}{a^2}+\dfrac{n_y^2}{b^2}+\dfrac{n_z^2}{c^2}}$$ which won't change much from $(1,0,0)$ to $(2,0,0)$ given that $a$ is large enough. Thus, even though $k$ can take discrete values, it doesn't hurt to as well skip certain $k$'s between $k$ and $k+dk$ and only talk about the region in phase space having the volume $4\pi k^2dk/8.$ (8 factor is to account for positive $k$'s)
Now, in the limit that the volume of the phase space cell is very low compared to $4\pi k^2dk$ the number of states can be comfortably calculated by the formula-
$$4\pi k^2 dk/8(\pi/a)^3$$ since one cell corresponds to one state in the limit of a unit cell's volume being very low.
