There are several things that promote spikes: oxidation, contamination with dissolved metal (like copper from the component leads, gold plating, etc.), temperature, and time.
Oxidation and contamination change how the solder behaves, causing it to get spiky, so you want to prevent these things.
Too low a temperature can cause spikes because the solder is barely melted and surface tension can’t pull it back.
Too high a temperature increases oxidation and increases contamination.
—> You need a temperature that is as low as possible, but as high as necessary. A larger soldering iron tip (and/or board preheating) let you use a lower tip temperature.
Flux prevents oxidation (and to an extent reverses it). So you need good flux in sufficient amounts. It doesn’t remain active forever, so if you’re taking a while on a joint, your flux may “wear out” and you will need to add some fresh flux.
And finally, experience lets you work faster, reducing the time it takes to make the joint — time when flux is wearing out, and oxidation and contamination are occurring.
If you have spikes forming, and even adding fresh flux doesn’t help, stop. Get rid of oxidized, contaminated solder from the tip (and maybe even the joint, too): Melt lots of fresh solder onto your tip and wipe it off. Do this a few times to rinse off all the oxidized, contaminated solder. Then go back and try to rework the joint with fresh solder and fresh flux.
It takes practice to figure out what temperature is right for each solder, tip, and even the joint itself.