This is where I couldn't figure out his motive. He clearly wants to maintain his reign, but if so, why did he start provoking in the first place?
Why he needs to go precisely this far is a good question. Possibly because Trump has consistently misplayed his hand and made a series of stupid bluffs that were quick and easy to call. Kim is probably testing the edges of his geopolitical box, figuring that it's a bit roomier than he'd previously calculated.
The nukes are to make them too dangerous to invade.