Struggling with the weight gain


I’m feeing really horrible about myself after getting chewed out by a doctor for having gained 21 pounds at 30 weeks. I’ve lost 3 pounds so my weight gain is at 18 pounds now but that’s just from 8 weeks. I’ve gained a few more than that total. Pictures are from 8 weeks to 32 weeks. How do I keep from gaining anymore fat without going too extreme. I know pregnancy isn’t the time to have fitness goals but I’m struggling.