Ive had knee pain and ankle problems in the last year nothing serious but a few lessons I've learnt as i got older,
first make sure your bike is set up correct,or if you run you have good trainers,if you do over do exercise listen to your body it needs to rest and repair,if you have a problem or pain think about why it hurts or how it happens,i then go to the physio,
make sure you stretch before and after,when muscles get tight they can damage i.e. my calves were tight due to riding, ignored it ran 40 miles over a week and bang my achilles tendon where it joins my ankle gave me big grief,a bit of stretching and care by my physio I'm a new man again,but if you ignore a pain you seem to inherit a secondary injury,
some riders think reel men don't stretch,believe me by stretching down after a ride will save you in the long term,
most muscles in the legs if they get tight can eventually effect your knee,when you ride,i have improved my flexibility in my legs with pilates and this has helped my legs,a trip to a physio will alleviate any fears a good deep muscle rub,repair and exercise prescription will make you feel new,two visits always seems to get me going again normally costs £80 but to me money well spent,
good luck and safe riding