In theory, it should indeed be equal as holding a bond $B_t$ from some company $X$ as well as paying on a CDS written on the bond should earn you the risk-free rate, given the CDS hedges the default risk of your bond.
In practice, there is a CDS-bond basis, which is equal to:
$$ \text{Basis}_{\text{ CDS-Bond}} = \text{Premium}_{\text{ CDS}} - \text{Spread}_{\text{ Bond}} $$
Where $\text{Premium}_{\text{ CDS}}$ is the CDS annual premium and $\text{Spread}_{\text{ Bond}}$ the difference between the bond yield and the risk-free rate.
AFAIK historically these basis have been positive: indeed, in a CDS your credit exposure is higher than with a bond because you are not only exposed to the credit risk of $X$ but also to the credit risk of the counterparty with whom you have entered the CDS trade.
However, again AFAIK, I think since the crisis they have turned negative quite often. This is often due to changes in demand and supply dynamics, normally due to regulation or practical trading issues. For example, under Basel II rules CDS were capital-relief instruments because they allowed banks to compress regulatory capital for credit risk, but since then Basel rules have changed (Basel III now) and the favorable treatment of CDS has been restrained, driving down CDS trading significantly $-$ before the crisis, I believe I read somewhere between 50% to 80% of CDS trading was driven by capital-relief trades by banks; unfortunately I am unable to find the source.