8. Given $f(x)=\sum_{k=1}^{2017} \frac{\cos k x}{\cos ^{k} x}$. Then $f\left(\frac{\pi}{2018}\right)=$
8. -1 .

Notice that,
$$
\begin{array}{l}
f(x)+\frac{\sin x}{\sin x} \\
=\frac{\sin 2 x}{\sin x \cdot \cos x}+\sum_{k=2}^{2017} \frac{\cos k x}{\cos ^{k} x} \\
=\frac{\sin 3 x}{\sin x \cdot \cos ^{2} x}+\sum_{k=3}^{2017} \frac{\cos k x}{\cos ^{k} x} \\
=\frac{\sin 2018 x}{\sin x \cdot \cos ^{2017} x} .
\end{array}
$$

Therefore, \( f\left(\frac{\pi}{2018}\right)=-1 \).