What were the primary reasons that people chose to join monasteries and convents during the Middle Ages?

What roles did monasteries and convents play in shaping medieval society and culture?