I was able to find the general solution of the given differential equation: $ \frac{dy}{dx} + \frac{cos(x)}{sin(x)}y = \frac{1}{cos^2(x)sin(x)}$.
The general solution is y = sec(x) + csc(x)C.
Now I don't get it how to find the largest interval(interval of validity). All I know are sec(x)= 1/cos(x) is undefined if cos(x) is equal to 0, that is, the value $ \frac{\pi}{2} + \pi n $ for all integers n, and csc(x)=1/sin(x) is undefined if sin(x) is equal to 0, that is, the value $\pi n$ for all integers n.
If you multiply with $\sin x$, you get the integrable equation $$ (\sin(x)y(x))'=\frac1{\cos^2x}\implies \sin(x)y(x)=\tan(x)+C $$ which gives directly the cited solution.
You have correctly identified the singularities of that solution formula. An ODE solution has its domain restricted such that the function is continuously differentiable over this domain. This means that the available domains are $(k\frac\pi2,(k+1)\frac\pi2)$, $k\in\Bbb Z$. The exact domain depends on where the initial point is given.
It is in general true that solutions for $$ y^{(n)}(x)+a_{n-1}(x)y^{(n-1)}(x)+...+a_1(x)y'(x)+a_0(x)y(x)=r(x) $$ have as maximal domain the maximal open interval that contains the initial time or position and such that all coefficients $a_k(x)$ and the right side $r(x)$ are continuous over this interval.