The supply of "subsidy"— newly created coins— declines exponentially over time. So a long time before all 21m is mined, sometime around the year 2140 the amount of new coins created this way will be insignificant.
Bitcoin transactions can optionally provide transaction fees which are paid to the first miner to include their transaction. Blocks have a limited size in order to prevent the biggest nodes from centralizing the system by producing more load than smaller ones can handle, so there will be competition for access to that limited space. Miners can then be funded collecting these fees.