Keto 5 years here. One thing that hasn’t been mentioned yet is the kidneys. They’re responsible for retaining salts (K, Na, Mg, Ca etc, they’re all ‘salts’) if you’re low or dumping them if you’re high. You have more than double the amount of kidney power you need (unless you have high hemoglobin A1c for years or have given away a kidney). If your kidneys are healthy, taking even double the amount of salts that you need is no problem at all. If you’re not taking enough, though, you’re kidneys can’t retain what isn’t there. I think it’s better to overdo the salts than take only small amounts.
Here’s my solution. I take Mg citrate or glycinate (not oxide) pills daily and add a lot of salt to my meals. If I’m having food that doesn’t go with salt, I occasionally drink water with 1/4 tsp table salt and a dash of potassium chloride. As a woman, they say we need more calcium then men, particularly when we’re post menopausal. So I also take calcium every other day and multivitamins every other day. I don’t know if it’s helping, but it’s not hurting and if I’m taking too much, my kidneys can deal with it. You’d have to take very large amounts of calcium to get kidney stones unless you have some type of metabolic difference from the run of the mill human.
I also drink a LOT of water during the first half of the day. (It’s a pain if I’m doing errands and I know where all the restrooms are at the stores I go to!). If you don’t drink a lot of water, you’re kidneys don’t have anything to work with. By 3pm, I stop drinking and only drink after that if I look back and see I haven’t managed to drink enough water that day. At that point (4-7pm) it’s thirst that prompts me to look back. About half the nights I get up at 5am to pee and the other half I don’t need to get up at all.
I haven’t had nighttime leg cramps since I started the magnesium pills. I heard that taking your Mg at night helps with sleep. I don’t know if it’s made any difference, but I take the Mg before bedtime.
Bottom line, I take 1.5 to 2x more of the salts than you think you need with extra water in the mornings and let the kidneys do the fine tuning. That’s my n=1 solution to the electrolyte problem.
P.S. Early physicists called them electrolytes because with them, water conducts electricity and early chemists called them salts and later realized that they were talking about the exact same thing. For some reason, medicine chose to use the term electrolytes instead of salts. There’s LOTS of them, but only K, Mg, Na, Ca are important enough for us to focus on.