Does the octet rule only apply to the second and third shell or does it apply further?
The shell concept is useful rather for 1-electron hydrogen-like atoms, where energies of ns, np, nd, nf orbitals are all the same ( well, not fully true due the very tine QED effect of interaction of electrons with quantum vacuum ).
For multielectron atoms, energy wise, $\mathrm{nd}$ orbitals from originally nth shell belong now rather to the (n+1)th shell. Similarly, $\mathrm{nf}$ orbitals from originally nth shell belong now rather to the (n+2)th shell.
So the octet rule for the 4th and higher periods have limited applicability for the $\mathrm{s}$ and $\mathrm{p}$ orbitals only for groups 1-2 and 13-18. It is not applicable for transition metals involving partially occupied $\mathrm{d}$ or $\mathrm{f}$ orbitals.