I had a bad case of runner’s knee in 2008… from running. The causes? Ramping up the mileage too quickly and muscle imbalance/weakness.
If the case is bad, then you have to take some time off to let your body repair the existing damage. Then you have to focus on how to prevent a recurrence. A proper bike fit is a good idea. So are proper cleat float adjustments.
You can also make your knee stronger with some strength exercises. A common factor in runner’s knee is a weak VMO, the medial/inner part of the quad. When that part of the quad is weaker than it should be, it doesn’t hold the kneecap in place correctly as you bend your knee during athletic activity.
A good exercise to work the VMO is the deep squat, where your thigh goes below parallel to the ground. If you don’t have good flexibility and strength, you need to work your way up to this range of motion gradually. In addition to that, always warm up before doing any strength training. Ten to fifteen minutes on an elliptical or stationary bike should be enough for an indoor workout. And when you do any sort of strength exercise, balance out the work so that the antagonist muscle groups get a similar amount of work.
Thus, if you do some sort of deep squat (which works the quads, glutes and hips), pair it up with an exercise that focuses on the hamstrings, lower back and hips.
Compound exercises (more than one joint used at the same time, such as the knees, ankles and hips for squats) should be the base of your strength routine. Machines can be used for supplemental exercise but it’s not a good idea to rely solely on machines for strength training.
You don’t have to spend a lot of time on this, but it’s good to do strength workouts on a consistent basis, maybe more in the winter and less in the spring and summer as you spend more time riding outdoors. Adding some core exercises are good too for general fitness and injury prevention.
I don’t think stretching will do too much. While post-workout stretching is usually a good idea, it can’t fix bigger problems with muscle imbalances. Only strength exercises will fix those problems. When I do post-workout stretching, I include stretches for the quads, hamstrings, calves, shins, bottom of feet, hip flexors, lower back, inner thighs and outer thighs/ITB as well as upper body stretches. Don’t neglect the inner/outer thigh stretches. While IT band problems are more often associated with running, I’ve heard of some cyclists having IT band issues too. A combination of balanced strength training and post-workout stretching can help avoid ITB problems.
By the way, when I developed runner’s knee, my knee would click very loudly every time I bent it. The kneecap was scraping against the side of the groove when it should normally slide inside that groove without any contact with the sides. Each scrape was scuffing the cartilage, causing damage and significant pain. I stopped running for several weeks to let the cartilage heal. I also resumed strength training (which I’ve done on and off for many years). The knee clicking stopped within a week of resuming strength training, a clear sign that the ST was working. ST didn’t heal the existing damage but it did help to prevent future problems. I’ve continued to run and bike in the following years. I’ve never had another problem with runner’s knee since I fixed the problem in 2008, although I did have sore knees during many runs in 2009 because I was still doing too much for my then current fitness level. After I took a break in fall 2009, resumed with a gradual base training program and kept up with strength training, the remaining knee issues went away. I haven’t had any knee injuries since 2008 and no knee soreness at all since early mid 2009, even while I did quite a lot of running and cycling (and swimming) in the years since.