Like with most of Poe's short stories that brim with creepiness, tension, and everything morbid, the ending of "The Cask of Amontillado" gets foreshadowed throughout the build-up to it.
(Spoiler alert. The story ends when the narrator, Montresor, gets revenge on Fortunato by basically burying him alive: trapping him in a vault and walling him up there.)
As the story opens, the narrator reveals directly to us that he's going to take revenge on Fortunato by exploiting the man's obsession with and knowledge of fine wines. But even if we didn't know that already, we could pick up on more foreshadowing as the story continues.
Check out these lines that directly foreshadow that grim ending:
"There were no attendants at home; they had absconded to make merry in honour of the time. I had told them that I should not return until the morning, and had given them explicit orders not to stir from the house. These orders were sufficient, I well knew, to insure their immediate disappearance, one and all, as soon as my back was turned."
This happens right as Fortunato is going to Montresor's house with him. We know that something awful is about to happen if Montresor has told all of his servants to make themselves scarce. (He doesn't want any witnesses if he's about to commit a terrible crime.)
A moment later, "the bells upon his cap jingled as he strode." Fortunato is wearing some kind of party hat with jingle bells on it, which is hilarious: he's literally a fool, marching forward willingly toward his own death.
Then this bit of dark humor also happens: Fortunato has a coughing fit because something in the atmosphere of the vault irritates him. But he says, "I shall not die of a cough," and Montresor replies "True, true." By this point, we know that Montresor is definitely going to murder Fortunato. So the fact that Montresor agrees that it won't be the cough that kills Fortunato is not just foreshadowing but also darkly funny.
Before the murder finally happens, there's actually a lot more foreshadowing of it. Here's one more example, when Montresor tells Fortunato about his family's coat of arms and their family motto:
"A huge human foot d'or, in a field azure; the foot crushes a serpent rampant whose fangs are imbedded in the heel."
"And the motto?"
"Nemo me impune lacessit."
Right then, Montresor is telling Fortunato that his family's coat of arms has a foot crushing the snake that bites it and that their motto is Latin for "No one attacks me with impunity" (meaning "nobody gets away with attacking me"). He's literally telling his soon-to-be victim that his chief family value is taking revenge on people.