The Korean War came about because of the Cold War. It had its origins in the last days of World War II, when the Allies were just about to defeat Japan and were already jockeying for power in the post-war world.
At the end of WWII, the Soviet Union joined in the war against Japan. It began fighting only after the first atomic bomb had been dropped by the US on Japan. Although the USSR was not in the war very long, it occupied (among other things) the northern part of the Korean Peninsula. The US occupied the southern part of the peninsula. This led to the creation of two countries; a communist North Korea and a non-communist South Korea.
Early in 1950, the American Secretary of State, Dean Acheson, gave a speech in which he appeared to say that the US would not defend South Korea. Having heard this, North Korea decided to attack the South because it wanted to reunify the country under communist rule. North Korea attacked in June of 1950. The US, however, felt that this was an example of communist aggression that had to be resisted. Therefore, it, along with a coalition of other countries, entered the war.
Thus, the Korean War came about because Korea had been divided along Cold War lines and the communist side felt it would be able to attack and defeat South Korea.