This usually results from the patella (kneecap) travelling a bit laterally (kicking sideways) during knee flexion especially under load. Most often the cause of the lateral movement is an imbalance between the vastus medialis and the vastus lateralis — with the lateralis overpowering the medialis and tugging the kneecap slightly to the outside. The solution is a process (long and incremental, i.e. no quick fix) and usually is best accomplished by increasing the strength of the medialis and adjusting the Q-Factors (tread-width of your feet) to insure straight up and down tracking through the pedal arc.
Bill Black