Pyelonephritis can happen:  When bacteria enter your urinary tract through the urethra. When bacteria from an infection somewhere else in your body spread through your bloodstream to your kidneys. After kidney surgery. All of the above.