8. Let $x \geqslant y>0$. If there exist real numbers $a, b$ such that $0 \leqslant a \leqslant x, 0 \leqslant b \leqslant y$,
and $(x-a)^{2}+(y-b)^{2}=x^{2}+b^{2}=y^{2}+a^{2}$.
Then the maximum value of $\frac{x}{y}$ is ( ).
(A) $\frac{2 \sqrt{3}}{3}$
(B) $\sqrt{2}$
(C) $\frac{\sqrt{6}}{2}$
(D) 1
8. A.

In the rectangular coordinate system $x O y$, construct rectangle $O A B C$ such that $A(x, 0)$, $B(x, y)$, and $C(0, y)$.

Take points $P$ and $Q$ on sides $O A$ and $A B$ respectively, such that $P(a, 0)$ and $Q(x, y-b)$.

From equation (1), we get $|P Q|=|Q C|=|C P| \Rightarrow \triangle C P Q$ is an equilateral triangle. Let $\angle O C P=\theta\left(0 \leqslant \theta \leqslant \frac{\pi}{6}\right)$. Then $\angle B C Q=\frac{\pi}{6}-\theta$. Therefore, $\frac{x}{y}=\frac{|B C|}{|O C|}=\frac{|B C|}{|C Q|} \cdot \frac{|C P|}{|O C|}$ $=\frac{\cos \left(\theta-\frac{\pi}{6}\right)}{\cos \theta}=\frac{\frac{\sqrt{3}}{2} \cos \theta+\frac{1}{2} \sin \theta}{\cos \theta}$ $=\frac{\sqrt{3}}{2}+\frac{1}{2} \tan \theta \leqslant \frac{\sqrt{3}}{2}+\frac{1}{2} \tan \frac{\pi}{6}=\frac{2 \sqrt{3}}{3}$.

Equality holds if and only if $\theta=\frac{\pi}{6}$. Therefore, the maximum value of $\frac{x}{y}$ is $\frac{2 \sqrt{3}}{3}$.