Steven Saint had the large kitchen knife with him when police arrived at a house in Sutton Bridge to detain him.
Jonathon Dee, prosecuting, said the officer who initially arrived at the property retreated out of the building and called for back-up after being confronted by Saint holding the weapon.
Mr Dee said: “Other officers arrived in full riot gear. The defendant had barricaded himself in a bedroom.
“They tried to talk him round but he repeatedly told them to go away and said he was going to kill himself.”
Worksop nuisance banned from town centre for abusive language and drinking alcohol
Police issue warning after man arrested for starting Bassetlaw grass fire
Cause of huge Creswell blaze a mystery after ‘major incident’ saw residents flee 50 homes
The latest rogues' gallery of criminals jailed in Nottinghamshire
Widowed Bassetlaw author set to release final book in the ‘Hugo and Daddy’s’ series
Police forced their way into the room but as they entered Saint twice struck out with the knife only for both blows to be blocked by an officer’s riot shield.
Mr Dee added: “The officers withdrew and regrouped.
“He was told he was going to be tasered if he didn’t surrender himself.
“He didn’t surrender and ultimately the taser was deployed.”
Mr Dee said the rape occurred earlier in the day when Saint carried out a violent attack on a woman.
After carrying out the rape he then kicked the woman.
Saint, 37, of no fixed address, admitted two charges of rape involving the same victim on August 14, 2015.
He also admitted a further charge of assaulting a police officer on the same date with intent to resist arrest.
John McNally, defending, said Saint should be given credit for pleading guilty to the offences.
He said Saint has shown remorse and self-loathing for what he did.
After the hearing Detective Constable Jacquie Crozier of Lincolnshire Police, said: “Steven Saint has pleaded guilty and starts his sentence.
“My thoughts are with the victim who has shown particular strength and bravery against a violent man.”