I think that this problem can be partially conquered by recursion. For illustrative purposes, this response will assume that $~k = 7.~$ The procedure should be clear enough to generalize, for any specific $~k \in \Bbb{Z^+}.~$
However, admittedly, this is a partial misinterpretation of the problem. That is, the OP (i.e. original poster) is (presumably) asking for $~f(k),~$ which is to equal the positive integer $~n,~$ as a function of $~k.~$ So, in effect, my response is taking the cowards way out.
As my further act of cowardice, the OP is actually looking for a function $~f(k,\epsilon) = n,~$ where $~n~$ is the smallest positive integer such that the probability of not having $~k~$ consecutive heads, anywhere in the sequence, is less than $~1 - \epsilon.~$
Again, for illustrative purposes, I will assume that $~\epsilon = 0.038$
For $~k \in \{0,1,2,\cdots,6\}, ~n \in \Bbb{Z^+},~$ let $~g(k,n)~$ denote the number of sequences of length $~n~$ that do not contain $~7~$ consecutive heads, but that have exactly $~k~$ trailing heads.
Let $~g(n)~$ denote the denote the number of sequences of length $~n~$ that do not contain $~7~$ consecutive heads.
So, it is desired to find the smallest positive integer $~n,~$ such that $~\dfrac{g(n)}{2^n} < 1 - \epsilon = 1 - 0.038.$
In general, you have that
$~\displaystyle g(n) = \sum_{k=0}^6 g(k,n).~$
$g(n+1,0) = g(n),~$ since you are forced to append a tails.
$g(n+1,k+1) = g(n,k) ~: k \leq 5,~$ since you are forced to append a heads.
As a consequence of the above bullet points, you have that
$g(n+2,1) = g(n+1,0) = g(n).$
$g(n+3,2) = g(n+2,1) = g(n).$
$g(n+4,3) = g(n+3,2) = g(n).$
$g(n+5,4) = g(n+4,3) = g(n).$
$g(n+6,5) = g(n+5,4) = g(n).$
$g(n+7,6) = g(n+6,5) = g(n).$
This implies that (in general) $~\displaystyle g(n+7) = \sum_{k=0}^6 g(n+k).~$
This leads to the following table:
\begin{array}{| r | r | r | r | r | r | r | r | r | }
\hline
n & g(n,0) & g(n,1) & g(n,2) & g(n,3) & g(n,4) & g(n,5) & g(n,6) & g(n) \\ \hline
7 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & 2^7 - 1 \\ \hline
8 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^8 - 3 \\ \hline
9 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^9 - 8 \\ \hline
10 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^3 & 2^{10} - 20 \\ \hline
11 & 2^{10} - 20 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^{11} - 48 \\ \hline
12 & 2^{11} - 48 & 2^{10} - 20 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^{12} - 112 \\ \hline
13 & 2^{12} - 112 & 2^{11} - 48 & 2^{10} - 20 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^{13} - 252 \\ \hline
14 & & & & & & & & 2^{14} - 572 \\ \hline
15 & & & & & & & & 2^{15} - 1271 \\ \hline
\end{array}
Then,
$$572 \div 2^{14} \approx 0.035, ~~~ 1271 \div 2^{15} \approx 0.039.$$
So, adopting the syntax at the start of my answer, $~f(7,0.038) = 15.$
Personally, I question whether the above recursion can be generalized.
If you hold $~k~$ fixed at $~7,~$ and are trying to find a closed form formula for $~f(7,\epsilon),~$ then you would have to somehow find a closed form formula for $~a_n,~$ where
$$a_7, ~a_8, ~a_9, ~\cdots, a_{15} = ~1, ~3, ~8, ~\cdots, ~1271,
~\text{respectively}.$$
Even if the above analysis was feasible, in order to generalize to any value of $~k,~$ you would (for example) have to generate similar tables for $~k = 8, ~k = 9, ~k = 10,~$ and then look for patterns between the tables.
On the other hand, if you accept the cowardly re-interpretation of the problem that $~k~$ and $~\epsilon~$ must be specified (up front), and you allow computer assistance, then the problem is conquered.
For example, suppose $~k = 10, ~\epsilon = 0.3.$
Then, you would have variables $~g(n,0), ~\cdots, ~g(n,9),~$ and the first row of the table would be
\begin{array}{| r | r | r | r | r | r | r | r | r | | r | r | r | }
\hline
n & g(n,0) & g(n,1) & g(n,2) & g(n,3) & g(n,4) & g(n,5) & g(n,6) & g(n,7) & g(n,8) & g(n,9) & g(n) \\ \hline
10 & 2^9 & 2^8 & 2^7 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & 2^{10} - 1 \\ \hline
\end{array}
Once the first row of the table is given, it then becomes routine to programmatically extend the table indefinitely. Then, it becomes a simple matter to programmatically identify the first value of $~n,~$ such that $~\displaystyle \dfrac{g(n)}{2^n} < 1- \epsilon = 1 - 0.3.$