Different words decline differently depending on the gender and the type of the ending.
Typically, for masculine in Locative the ending is -і if the noun ends with "softer" kinds of consonants. From my native speaker perspective, those consonants are easily softened by -і. For example, ні is very easy to pronounce, the н sounds soft like the Spanish ñ. But кі is hard and uncomfortable to pronounce, the softening of к is not so smooth.
So for example, these endings tend to have -і in Locative: -ж (на ножі), -з (у розрізі), -л (на столі), -м (у храмі), -н (у стані), -п (в окропі), -р (на дворі), -с (у лісі), -т (на капоті but в аеропорту). And all of the consonants are more or less easily softened.
The harder ones tend to have -у: -д (у саду, but for example also, у комоді), -к (на знаку), -х (на даху).
As you can see, д and т are unclear, as their soft forms are quite OK. To be fair I myself had to search whether it's "в аеропорті" or "в аеропорту". I don't say this word often, so I forgot the form; and it sounds equally OK to me (so like, the neural network in my brain which decides what sounds natural and OK couldn't decide)
But for "-к" it's definitely always "-у"