Sorry boys - that's an urban myth.
Can you imagine a (relatively) small fighting ship of the sixteenth through early nineteenth centuries with pyramids of cannonballs on the decks? One small wave or blow of the wind in the sails and they'd be rolling around the deck (bit like a loose cannon
) fracturing toes, ankles and shins.
No - cannonballs were stored near the cannons but in wooden holders called garlands which were fastened securely to the inside of the hull. (This also provided a layer of metal which gave some re-inforcement to the hull against enemy fire.) Further stores were kept lower down (to aid the centre of gravity of the ship) and brought up as needed by "powder monkeys" (usually junior ratings) who brought them to the guns along with needed gunpowder.
The phrase originated in the US and was sometimes used in conjunction with the weather "freeze (or sometimes melt) the
tail off a brass monkey." This became "balls" in less polite circles.
"Ooooh! Arrrrr! and Buck Ho!.....Me hearties!" Cap'n Gold has spoken.