Let $x_1, x_2, \ldots, x_n \ge 0$ are nonnegative reals, subject to the constraint $x_1 + x_2 + \cdots + x_n = k$. We reason by induction that the maximum value of the product $x_1 x_2 \ldots x_n$ is attained when $x_1 = x_2 = \ldots = x_n = k/n$.
First, the case where $n = 2$ was already addressed. So in the case $n = 3$, suppose $x_3$ is fixed, hence the maximum occurs when $x_1 = x_2 = (k - x_3)/2$ and the resulting product is $x_1 x_2 x_3 = (k - x_3)^2 x_3/2$. Now if $x_3$ is allowed to take on different values in $[0,k]$, the fact that the product is maximized when $x_1 = x_2$ remains true, so we can argue that as a function of $x_3$, the product is maximized for some critical point of this function, namely $$0 = \frac{d}{dx_3}\left[\frac{(k - x_3)^2 x_3}{2}\right] = (k - x_3)x_3 + \frac{(k - x_3)^2}{2}.$$ Solving the quadratic results in $x_3 = k$ (which obviously corresponds to a minimum) and $x_3 = k/3$. A convexity argument indicates this yields the desired maximum, and $x_1 = x_2 = x_3 = k/3$.
The above is naturally extensible. For suppose that we have established that the product is maximized on $n$ variables when all are equal to $k/n$. Then for $n+1$ variables, consider $x_{n+1}$ fixed, so the product is $$x_1 x_2 \ldots x_n x_{n+1} = \frac{(k-x_{n+1})^n x_{n+1}}{n}.$$ Searching for the critical point with respect to $x_{n+1} \in [0,k]$ yields $x_{n+1} = k/(n+1)$, hence $x_1 = x_2 = \ldots = x_{n+1} = k/(n+1)$ and this completes the induction step.
Now, if $x_1, \ldots, x_n$ are nonnegative integers, the above reasoning does not work because we cannot compute critical points to obtain extrema. Instead, we reason more simply. Suppose $x_1 + \cdots + x_n = k$. Then adding $1$ and subtracting $1$ from $x_i$ and $x_j$ respectively, for $i < j$ (without loss of generality), yields the same sum, but the product becomes $x_1 x_2 \ldots x_n$ to $x_1 \ldots (x_i + 1) \ldots (x_j - 1) \ldots x_n$. If we take the ratio, we find this is $$\frac{(x_i + 1)(x_j - 1)}{x_i x_j} = \frac{x_i x_j - x_i + x_j - 1}{x_i x_j} = 1 - \frac{1}{x_j} + \frac{1}{x_i} - \frac{1}{x_i x_j}.$$ So if $x_i = x_j - 1$, this ratio equals $1$, and the value of the product remains unchanged. From this, we can see that if $x_i \ge x_j$, then incrementing $x_i$ by $1$ and decrementing $x_j$ by $1$ will decrease the product, and if $x_i < x_j - 1$, it will increase the product. This is irrespective of the values of the other factors in the product.
Hence, if there exists $i \ne j$ such that $x_i < x_j - 1$, repeatedly incrementing $x_i$ and decrementing $x_j$ so that $|x_i - x_j| \le 1$ will increase the value of the product. Again without loss of generality, order the terms in nondecreasing sequence, so that $x_i \le x_j$ for all $i < j$. Then we can see that we must have $|x_n - x_1| \le 1$, which implies that there is a $m$ such that $x_1 = \ldots = x_m$, and $x_{m+1} = \ldots = x_n = x_m + 1$, or $$mx_1 + (n-m)(x_1+1) = (n-m) + nx_1 = k.$$ Since all of these variables are nonnegative integers, we require $n$ to divide $k+m$. Since $1 \le m \le n$, such a choice of $m$ is unique as there is only one representative of the equivalence class of integers modulo $n$ that is the additive inverse of $k$, namely $m \equiv -k \pmod n$. As this choice is unique, the corresponding product must be the maximum attainable over the nonnegative integers.
An example of this maximization for $n = 7$, $k = 45$: we select $m \in \{1, \ldots, 7\}$ such that $45+m$ is divisible by $7$. This of course is $m = 4$, hence $x_1 = x_2 = x_3 = x_4$ and $x_5 = x_6 = x_7 = x_1 + 1$. We must have $7x_1 + 3 = 45$, or $x_1 = 6$, and the maximum product is $6^4 7^3$.