they always go for glory. That's why heroes usually have a short life. And it'S really difficult to teach players that they're not the center of the world and not every encounter is at most "challenging". That there are also encounters that might kill them. As it is, it's also difficult in most systems to withdraw from combat or give it up without casualties (and giving up... you NEVER give up!

).
While I agree to some extent, usually when the party doesn't recognize a potentially lethal encounter as such, it's DM fail rather than player fail.
Suppose you've got a 6th-level party facing a gang of ten orcs with a one-eyed orc leading them. Those orcs could be 1st-level grunts led by a 3rd-level lieutenant, easily cleaned up with a
fireball from the wizard and a few whacks from the fighter. Or they could be the 10th-level elite bodyguard of a 15th-level high priest of Gruumsh, a TPK in spades. D&D offers no easy way to tell by looking. Even when DMs think they're giving clues about the encounter difficulty, the clues are usually much more ambiguous and less useful than the DM thinks they are.
D&D characters expect to get into fights. It's part of the game. When presented with what looks like a combat situation, against foes who are not clearly superior, it's hardly surprising that the PCs draw swords and attack. Once the fight starts going badly--as you say, most systems make it tough to withdraw from a fight. Somebody will almost certainly get left behind, and no player wants to do that.
As a DM, there
are ways to get the message across, but you have to be unambiguous about it. If my PCs enter a dragon's lair and I want to convey that this dragon is out of their weight class, I don't portray it as Large or Huge. I grab
Big Red and bang him down on the table. If they meet an orc warband and I want them to realize a head-on confrontation isn't going to work, the warband isn't going to have twenty orcs in it--it'll have two hundred. Or, after giving them a tough battle against a single monster of a given type, I'll have them run into nine or ten of the same critter.
If, in
these situations, they still pick a fight, I'll serve up a TPK sandwich with all the trimmings. But if they get into a fight with a gang of orcs that just happen to be a few levels higher than they expected, I'm not going to claim that they should have somehow known better. And if for some insane reason I have an overwhelmingly superior foe initiate hostilities, I'm not going to blame the players if they stand their ground and die like heroes instead of running away.