It’s not easy. Two things that seem to be really important for me:
In the morning I have multiple iPhone alarms to wake me up and a physical alarm clock across the room to get me out of bed. The one inviolable rule is that once the alarm clock gets me out of bed, no going back to sleep. That gets me up at the same time every morning.
I also try to go to bed at the same time each night. I’ll admit that I’m not as consistent about this as the getting up part. In part, that’s because getting to bed at the same time every night is harder. But it’s also because staying up late doesn’t screw me up as much as sleeping in would. If I stay up a couple of hours I’ll be miserable the next day. If sleep in a couple of hours it’ll throw me off for a week. As long as I go to bed early enough to get 8 hours in most of the time it seems to work OK.