The most important thing you can do to stop generals rebelling is to build up the authority of your king. No-one wants to serve a ruler they don't respect, and in the middle ages respect was earned by battlefield success. So get your king out of his castle, and get him kicking some butt, and your loyalty problems will disappear.

Of course you may still get problems when you have a new king, and haven't had time to build up his authority yet. Deciding whether to undertake major operations during this time, is part of the strategy of the game.

You will also face more rebellions when you get excommunicated, or the king dies.