They refer to the same thing, but there is some separation between the terms, especially in the military. A cockpit is a hole with a seat that you strap into for the entire flight. A flight deck is a larger version of a cockpit, where you can at least leave your seat and walk behind it.
The traditional nautical term "cockpit" referred to a fairly small steering station at the top of the ship. Boeing introduced the term "Flight deck" post-WWII for their larger aircraft, to indicate the difference, and it has spread somewhat. A heavy's flight deck is still a cockpit, and can be referred to as such, but a "pointy's" (jet fighter) cockpit is very unlikely to be called a flight deck in speech.
In general and civil aviation, the terms are pretty much interchangeable. Still, a Ultralight Aircraft's cockpit is not a flight deck, so there is a strong connotation of a flight deck actually being a deck.
The B-2 has a flight deck, so do some fighters like the Su-34. Both can be called a cockpit as well. Basically, solo or tandem seating with entry through the canopy = "cockpit". Side-by-side seating with side door or bottom hatch entry = either "flight deck" or "cockpit".
This distinction is largely English-specific. Powered flight was being concurrently developed in France and Russia, and many languages ended up following their convention ("Piloting post/cabin" and "Crew cabin" respectively), where no term distinction was ever created.