Hi-
We had the same issue with our 2 1/2 year old, around the time when she really understood that I was pregnant. I think it was cognitive development of being alone and/or the changes that she was understanding. Look for any changes in his life that might be a change or something for him and talk to him about it as well.
Our ultimate solution was: leaving the door open, letting her walk up to me seeing that I was doing something really boring (reading) and that I was available and near by. The very best of the solutions we had to implement was putting a gate on her door of her bedroom (room being childsafe completely). While we won't keep it on forever (probably take it off in a year or so), right now it has been an wonderful solution and she likes the comfort of feeling safe in her room. We also know that she is safe and not walking around the house. Not all children are this way though. My friend used a playpen as a punishment for getting out of bed and that did not work for us. She actually asked for it!
Also, reading "Solving Your Child's Sleep Habits" was VERY helpful in explaining their behaviors, sleep patterns, and solutions. We also stopped letting her get in our bed in the morning (at all for sleeping) and that helped too.
It is SO hard when they get out of bed constantly, don't get their sleep, and you don't get your's either. Try to your BEST to treat your child like a baby when he's having these issues as he's just a little child dealing with a fear and looks to you to help. Getting upset or frustrated will absolutely only hurt, not help.
I wish you the very best.