Let me provide by hand free groups in the variety $V_p$ generated by the dihedral group $D_{2p}$ of order $2p$, $p$ odd prime.
First observe that $D_{2p}$ satisfies the group identities $x^{2p}=1$, $[x^2,y^2]=1$.
In any group, let $G^2$ be the set of squares and $G_p$ the set of elements of order dividing $p$. For any group, $G_p\subset G^2$. For $G$ satisfying the identity $x^{2p}=1$, we have the reverse inclusion, and hence $G_p=G_2$.
In addition, the identity $[x^2,y^2]=1$ implies that for $G\in G_p$, any product of squares belongs to $G_p$, so the subgroup generated by $G^2(=G_p)$ is contained in $G_p$. This means that $G_p$ is a subgroup, obviously a normal elementary abelian $p$-subgroup. Since $G_p=G^2$, $G/G^2$ is a 2-group. If $G$ is finite, we deduce that $G=G_p\rtimes Q$, where $Q$ is any 2-Sylow subgroup, and $Q$ is elementary abelian (say of order $2^k$); for convenience write $Q=Q_k$.
The irreducible $\mathbf{F}_p[Q_k]$-modules are all 1-dimensional, given by the $2^k$ homomorphisms $\chi:Q\to C_2$; denote it by $V_\chi$. So we can write $G_p=\bigoplus_{\chi\in\mathrm{Hom}(Q,C_2)}V_\chi^{n_\chi}$.
Now let $G=G(k)$ be the free group of rank $k$ in this variety. Clearly $G/G^2$ is isomorphic to $Q_k$, so it remains to determine the multiplicities $n_\chi=n_\chi(k)$. The abelianization of $G(k)$ being isomorphic to $C_6^k$, we have $n_0(k)=k$. We have a canonical homomorphism $\mathrm{Aut}(G)\to\mathrm{Aut}(Q_k)\simeq\mathrm{GL}_k(\mathbf{F}_2)$. It is surjective: indeed if $(x_1,\dots,x_k)$ is a basis of $G$, then mapping $x_i$ to $x_ix_j$ ($i\neq j$ fixed) and fixing all other basis elements, induces the corresponding elementary matrix, and these generate $\mathrm{GL}_k(\mathbf{F}_2)=\mathrm{SL}_k(\mathbf{F}_2)$. It follows that all $n_\chi(k)$, for $\chi\neq 0$, are equal, say to some number $n(k)$, to determine.
First, we have $n(k)<k$ for all $k\ge 1$. To show this, fix $\chi\neq 0$, and we have to check that $V_\chi^k\rtimes Q_k$ is not generated by $k$ elements. Modding out by the kernel of $\chi$, this amounts to showing it when $k=1$, i.e., $\mathbf{F}_p^k\rtimes_{\pm}C_2$ is not $k$-generated. Indeed, consider $k$ generators $u_1,\dots,u_k$. We can suppose that $u_1\notin \mathbf{F}_p^k$. Then, replacing $u_i$ with $u_iu_1$, we can suppose that $u_1\in \mathbf{F}_p^k$ for all $k\ge 2$. Then, for if $k\ge 2$, modding out by the subgroup generated by $u_k$ (which is normal) shows that $\mathbf{F}_p^{k-1}\rtimes_{\pm}C_2$ is $(k-1)$-generated. We can continue until $k=1$ and deduce that $\mathbf{F}_p\rtimes_{\pm}C_2$ is 1-generated, which is a contradiction since it is not abelian.
Now I claim that $n(k)=k-1$. That is,
the free group $G(k)$ on $k$-generators in the variety $V_k$ is isomorphic to $((\bigoplus_{\chi\neq 0}V_\chi^{k-1})\oplus V_0^k)\rtimes Q_k$, where $Q_k\simeq C_2^k$, and where $\chi$ is meant to range over $\mathrm{Hom}(Q_k,C_2)$, and $V_\chi$ is $\mathbf{F}_p$ endowed with the action $q\cdot v=\chi(q)v$ of $Q_k$.
Given the above, it remains (a) to prove that this group is $k$-generated, which implies that $G(k)$ is indeed free in the variety generated by the identities $x^{2p}$ and $[x^2,y^2]$, and that $G(k)$ indeed belongs to the variety generated by $D_{2p}$.
(b) is easy: indeed, given any nontrivial $g$ element of $G(k)$, we have to find a homomorphism $G(k)\to D_{2p}$ such that $g$ is not in the kernel. If $g$ does not belong to $G(k)_p$, this is clear (map onto $Q_k$, and then to an element of order 2). Otherwise there exists a quotient of $G(k)$ of the form $V_\chi\rtimes Q_k$, and killing the kernel of $\chi$, we get, if $\chi\neq 0$ $V_\chi\rtimes C_2\simeq D_{2p}$, and if $\chi=0$ we get $V_0\simeq C_p$.
(a) (1) $H_\chi:=V_\chi^{k-1}\rtimes Q_k$ is $k$-generated, by some $k$-tuple mapping onto the canonical basis of $Q_k=C_2^k$. First suppose that $\chi$ is the $k$-projection. Then this writes as $C_2^{k-1}\times(\mathbf{F}_p^{k-1}\rtimes_{\pm} C_2)$, which is generated by $(s_1q_1,s_2q_1,\dots,s_{k-1}q_{k-1},q_k)$, where $(s_i)$ is the canonical basis of $\mathbf{F}_p^{k-1}$ and $(q_i)$ is the canonical basis of $C_2^k$. In general, this yields a generating $k$-tuple mapping onto some basis of $C_2^k$ (usually not the original basis). Using elementary operation, we deduce a generating $k$-tuple of $H_\chi$ mapping exactly onto the canonical basis of $C_2^k$.
(2) $V_0^k\rtimes Q_k$ has the same property: this is obvious since it is isomorphic to $C_6^k$.
We can conclude. For every $\chi$, we have a generating subset of $V_\chi^{n_\chi}$ of the form $((v_{\chi 1},q_1),\dots,(v_{\chi,k},q_k))$. Write $v_i=(v_{\chi,i})_\chi\in V=\bigoplus_\chi V_\chi^{n_\chi}$. I claim that $(v_1q_1,\dots,v_kq_k)$ generates $V\rtimes Q_k$. Since $(v_iq_i)^p=q_i$, the subgroup it generates contains $Q_k$, hence has the form $V'\rtimes Q_k$ with $V'$ some $Q_k$-submodule. Since $V'$ maps onto each isotypic component $V_\chi^{n_\chi}$, we have $V'=V$. So $G(k)\simeq (\bigoplus_{\chi\neq 0}V_\chi^{k-1}\oplus V_0^k)\rtimes Q_k$.
Note: Since $\bigoplus_\chi V_\chi$ is isomorphic to the regular representation $R_k$ (of $Q_k$ over $\mathbf{F}_p$), this can be rewritten as $(R_k^{k-1}\oplus V_0)\rtimes Q_k$ (which has order $p^{(k-1)2^k+1}2^k$). This confirms Keith Kearnes's conjecture, which motivated this additional answer.