Two quick knee helps to try out before you get into looking for complex physical causes too deeply: Do like Donna says- on a long ride keep sipping a drink with electrolytes. And raise your saddle height a cm or so- might help with "some" knee pains.

And do get some new shorts.

(JUST KIDDING!!!!)