Best way to prevent knee injury

Been cycling for a while and notice I get knee pains on and off. No major injuries but looking to avoid that as much as possible

Bike Fitting is a must, plus discuss with the doctor.