When you cast a spell that has an actual level given below its name, you choose (and expend) a slot equal to the spell's level or higher and the spell is cast at that level. This is all better explained on page 201 of the PHB. Some spells have additional effects that happen when you cast them using a higher level slot.
Cantrips however are a slightly different story; their spell level is 0, they don't expend spell slots and as such they can't be cast at a higher, or lower, level (PHB pg.201).
This means that there is no choosing the level at which it's cast because its spell level is always constant.
The extra effects gained by a cantrip aren't based on slot level but on your character level and are worded in such a way that doesn't give you a choice of whether they happen or not.
For example:
The spell creates more than one beam when you reach higher levels. (Eldritch Blast - cantrip)
or
This spell’s damage increases by 1d6 when you reach 5th level (2d6), 11th level (3d6), and 17th level (4d6). (Acid Splash - cantrip)
As opposed to spells that use slots:
At Higher Levels. When you cast this spell using a spell slot of 3rd level or higher, a target’s hit points increase by an additional 5 for each slot level above 2nd. (Aid - 2nd level spell)
2 levels of Warlock are enough for full Eldritch Blast damage
You are absolutely right, there is not much reason to go above level 2 with Warlock from an optimization standpoint, if you only want Eldritch Blast.
You get every benefit from Eldritch Blast, without giving up much in return, since cantrips scale with your character level, not your class level. You will have to consider however that Eldritch Blast requires Charisma, and that one is the usual dump stat of an Eldritch Knight. So you will either be quite bad at blasting, or sword swinging. Or both. There is no synergy in stats, playstyles, preferred distance, equipment, nothing.
It is great for others
As every DnD edition with character options, 5E rewards specialization. You either excel at standing in the back rows and sniping enemies, or be a front liner. There is not much middle ground.
For a Sorcerer or Bard, 2 levels of Warlock is golden, to have a really strong cantrip when they run out of real spells. But not for a Fighter.
So can you take 2 levels of Warlock, for full Eldritch Blast progression? Yes
Is Eldritch Blast worth it from an optimization standpoint for a Fighter? No
Other parts of Warlock might work better for you
However, if you do not focus on EB, Warlock can be a really good addition.
- Hex improves your DPR quite a bit, considering how many times a Fighter can attack on higher levels. Temporary hit points on a kill are also nice (Dark One's Blessing)
- 2 levels of Warlock double the number of slots per day, and you can get improved darkvision, even more hit points, or free Detect Magic (Invocations)
- 3 levels can give you quite a lot of great spells not belonging to the abjuration or evocation schools. Invisibility, Mirror Image, Phantasmal Force or Misty Step, all excellent for a Fighter
- An invisible scout (Pact of Chain) or rituals (Pact of Tome)
- 4 levels give you an ASI
- 5 levels can give you Fireball, Stinking Cloud, Blink, Fear, Counterspell, or Vampiric Touch and an invocation
- 6 levels can give you a teleport+invisibility, Temporary Hit Points, or Advantage on an attack depending on your patron
I would go like this:
- 1 Fighter level (saving throw/armor proficiencies)
- 2 Warlock levels (2 spell slots, 2 invocations, patron feature)
- 5 more Fighter levels (Extra Attack, ASI)
- 3 more Warlock levels (3rd level spells, 1 invocation, ASI, pact)
- Remaining levels in Fighter
Best Answer
Cantrips level with your character, not your class
While it never explicitly states this anywhere in basic or the PHB, it only states the level at which the cantrip increases in power. One of the design goals of 5e and one of the things it imported from 4e was that there should never be a time where a magic user is forced to resort to making a weapon attack that they are ill-suited for. Cantrips act like 4e's At-Will spells and as such level with each "tier" in 5e to maintain their usefulness. Tying this to character level means that players who multiclass or for example start off with a free cantrip (such as High Elves) are still able to make use of those cantrips throughout the whole of the game.
A clarification was added to the Sage Advice Compendium.
Later, this was added to the rules for multiclass spellcasters (PHB, p. 164) in the Player's Handbook errata: