Let $P(n,k)$ be the number of ways of doing this without the constraint that every number must appear at least once. Clearly $P(n,k) = k^n$.
Then note $P(n,k)$ contains $j^n$ arrangements containing only numbers from $1$ to $j$. So it might be tempting to say that there are $\binom{k}{j}j^n$ arrangements that only contain $j$ dfferent numbers or fewer however this is not the case. This is because if there are fewer than $j$ numbers used (say $l$) in the arrangement we can choose our $l$ numbers and then choose any other numbers we want and so each arrangement only using $l$ numbers is counted $\binom{k-l}{j-l}$ times.
Therefore $\sum_{l=1}^{j}\binom{k-l}{j-l}S(n,l) = \binom{k}{j}j^n$ where $S(n,l)$ is the number of arrangements using exactly $l$ different numbers. The answer to your question is $S(n,k)$.
Then by using inclusion exclusion we find $S(n,k) = \sum_{j=1}^{k}(-1)^{j+k}\binom{k}{j}j^n$.
Checking the $n=3,k=2$ case in your question gives $S(3,2) = \sum_{j=1}^{2}(-1)^{j}\binom{2}{j}j^3 = 8 - 2 = 6$ so it does indeed give the correct answer.