"Never take a knife to a gun fight"
Nearly everyone knows this. And it is good advice. But this assumes that there will be a fight. Most knife attacks are just that, attacks. Notice how so many of the situations discussed start with knife attack against a holstered gun? The 21 ft rule is used as a general legal reference, and is not a hard and fast physical fact.
Generally, if your attacker is within the magic 21 ft, you may be considered justified if you have to shoot him. If he is further away, it is difficult (not impossible, but exact conditions are critical) to be judged as needing to shoot.
I am not discounting knives, they are lethally effective, and have been since their invention. But they have drawbacks for defense. First, and foremost, they are a contact weapon. And second, they require a certain level of strength and mobility to be used effectively. A 97lb grandmother would have a much harder time defending herself against attack with a knife than with a gun, even a small gun like a .25 auto.
And when it comes to a fight between young, healthy men, the old saying is that in a knife fight, the winner goes to the hospital, the loser, to the morgue.
Knives work, no doubt. But against a drawn gun (any gun) in the hands of an aware (not surprised) individual, who is determined to defend themselves, and not just drive off the attacker or hold them at gun point (as police are trained to do) I would think the odds will favor the gun. By more than a little.