North Korea and the U.S. have escalated in recurrent cycles for decades, although the recent hostilities are the most intense since the early 1970s.
The constant irritant has been relentless U.S. pressure on the North, including frequent threats to the very existence of the regime, whose official name is the DPRK (Democratic People's Republic of Korea).
Since 2000, there have also been examples of regimes in Iraq and Libya that gave up nuclear weapons under U.S. pressure--and then were destroyed, either directly by the U.S. or with U.S. help. Those experiences convinced the DPRK regime that, once begun, there could be no turning back from building a nuclear deterrent.
The real attraction of building long-range nuclear weapons is that it could help the DPRK break out of the cycles of provocation with the U.S.--by creating greater parity of risk between the two parties.