In Minecraft, gunpowder is obtained by killing a Creeper. The easiest way is to get in close, then quickly back away as it explodes on its own.