7. The maximum value of the function $y=\tan x-\frac{2}{|\cos x|}$ is ( ).
(A) $1-2 \sqrt{2}$
(B) $1+2 \sqrt{2}$
(C) $-\sqrt{3}$
(D) $\sqrt{3}$
7.C.

To maximize $y$, we should have $\tan x > 0$.
Assume $0 < x < \frac{\pi}{2}$. Then
$$
y = \tan x - \frac{2}{\cos x} = \frac{\sin x - 2}{\cos x} < 0,
$$

which implies $\sin x - y \cos x = 2$.
Thus, $\sin (x - \theta) = \frac{2}{\sqrt{1 + y^2}} (\tan \theta = y)$.
From $\sin (x - \theta) \leq 1$, we get $\frac{2}{\sqrt{1 + y^2}} \leq 1$.
Solving this, we find $y \leq -\sqrt{3}$ or $y \geq \sqrt{3}$ (the latter is discarded).
Substituting $y = -\sqrt{3}$ into equation (1) gives $x = \frac{\pi}{6}$.
Therefore, $y_{\max} = -\sqrt{3}$.