there is a affix which provide sockets on magic and rare items, this affix can be spawn on the item again but the odds are very low.
You can use the recipe which grants sox on the next roll for magic weapons. This will set the itemlvl to 30. So most often not what you want.
You can sock an rare item with the Larzuk quest. (gives 1 sock)