The area of the triangle can be expressed as $$\frac 12ab=\frac 12a\sqrt{(k-a)^2-a^2}=\frac{a}{2}\sqrt{k^2-2ak}=\frac{\sqrt k}{2}\sqrt{a^2k-2a^3}$$
Here, let $f(a)=a^2k-2a^3$. Then, we have $$f'(a)=2ak-6a^2=2a(k-3a).$$ So, since we know that the maximum of $f(a)$ is $f(k/3)$, it follows that the maximum of the area of the trangle is attained when $a=k/3$.
Then, the angle $\theta$ satisfies $$\cos\theta=\frac{a}{\sqrt{a^2+b^2}}=\frac{k/3}{k-(k/3)}=\frac 12\Rightarrow \theta=\frac{\pi}{3}.$$