In the Game of Thrones season premiere, we see Cersei and Jaime Lannister struggle with almost being completely surrounded by enemies. They know that they need a powerful ally in this war if they are going to keep the Iron Throne, so they turn to Euron Greyjoy. But who is he and how exactly does he know Jaime Lannister?
We get some of their backstory when Euron comes to King's Landing, and the two men reference a battle — the Greyjoy Rebellion, which happened nine years before the events of the show. According to the books, the Ironborn, or natives of the Iron Islands, not only wanted independence, but to revert to the "Old Way," or their traditional lifestyle of reaving and plundering in the name of the Drowned God. Balon Greyjoy, Euron's brother (and Theon and Yara's father), declared himself the King of the Iron Islands, rebelling against current King Robert Baratheon, who himself had usurped the throne from Aerys Targaryen. Next, Balon planned the Raid on Lannisport, and Euron Greyjoy sailed to Casterly Rock and burned the Lannister fleet.
The Ironborn were eventually overtaken by Robert and his allies (which was pretty much everyone in Westeros besides the Greyjoys), and Jaime Lannister was able to take part in Robert's massive victory at the Siege of Pyke, which he and Euron are reminiscing about (at the time, Jaime is part of the Kingsguard and the fleet of ships belonged to his family). Jaime and Euron were both personally in that battle, and Euron even praises Jaime's fighting ability in the season seven premiere, despite losing the battle. Euron lost two of his nephews, Balon's sons, in the rebellion.
Euron had to go into exile after the defeat, but his Iron Fleet grew stronger. Balon Greyjoy surrendered to King Baratheon and was accepted back into the kingdom in peace in exchange for his son, Theon, staying with the Starks as a hostage.
On top of all this dramatic history, Jaime could also inherit Casterly Rock, an area that was once promised as a reward to Balon Greyjoy once the war between the North and Lannisters is over, since Casterly Rock is technically under rule of House Lannister.
So the Greyjoys, Lannisters, and Baratheons certainly have a fraught relationship, given they've gone to battle before. But it looks like the betrayal of their relatives is what is going to bring them together as allies, despite their complicated history.