Historically, knights were protected from firearms. Armour from the late 1400's on was "proofed" by firing a shot from a handheld firearm into it, allowing the purchaser to have a visible sign that the armour was capable of stopping a bullet.
Handgonne from the 1400's
Proofed suit of armour
The issue was that while it was possible to create armour which could stop bullets, it was increasingly heavy and inflexible, and also increasingly expensive to purchase. Essentially the cost was rising far faster than the effectiveness of the protection, and the diminishing returns caused armour to be abandoned until advances in material science created strong, lightweight materials like Kevlar, Spectrashield, titanium strike plates and ceramics capable of absorbing bullet strikes.
It should also be noted that metal armours were used against firearms even in the 19th and 20th century in very limited amounts. The Australian criminal "Ned" Kelly had a home made suit of armour which protected him from bullets (for a while), and various forms of metal armour were tested in the trenches during WWI. However, much like knights discovered in the 1500's, proofed armour capable of stopping bullets was heavy, restrictive and very expensive.
WWI British "Trench Armour"
Soldiers can be protected against modern firearms, but most soldiers are generally protected more against shell fragments and splinters for much the same reason that a medieval knight was not protected against firearms: Level IV armour capable of stopping full power rounds is bulky and expensive. The soldiers may need mobility and flexibility more than full protection.
SoF (Special Operations Forces) operators in Level IV armour
This suggests that a modern "Knight" may be kitted out as a SoF operator in Level IV armour, so able to withstand being shot by firearms (especially pistols, submachineguns/Personal Defense Weapons or assault rifles). However, in order to function effectively with a melee weapon, they would also need to be trained to avoid any area where they are in the open and exposed to shots, and only engage in melee combat at close range, such as ambushes inside confined spaces like buildings. Incidentally, this would actually reduce the effectiveness of actual knightly weapons: the primary arms were pole arms which provided extra reach and leverage for the knight to deliver a crippling or killing blow; swords were sidearms and for use when the user lost or broke a pole arm.
As for entire armies, modern armies have logistics which allow them to span the globe and enablers which enable them to operate and attack across the land, sea, air, space, cyber and cognitive domains, so any medieval army (even one with modern Level IV armour and titanium pole arms and swords) will simply have no chance at all. Being tracked by satellite, bombarded by aircraft or artillery and subjected to PSYOPS (Psychological Operations) attacks such as continual loudspeaker noises preventing sleep or effective communications, while having horses shot out from under them by snipers 2000m away using .50 BMG (50 Caliber Browning Machine Gun) sniper rifles without any possibility of response will eliminate them as a force in being, and that is without having them confront a force with modern AFV's (howArmoured Fighting Vehicle), how will knights fight against tanks and attack helicopters? Even IFV's (Infantry Fighting Vehicle) with 25mm cannon and machine guns will cut swaths through them from far beyond any possible response. Modern troops will clear buildings with explosives and flame weapons rather than engage on melee combat.
Knights? You've got to be kidding!
So while it is possible to protect a man with modern materials against firearms, there is no practical way to effectively fight against modern soldiers using medieval weapons, tactics or military organizations.