[verb た-form] + 甲斐がある [verb (dictionary form)] + 甲斐がある [noun] + の + 甲斐がある [verb ます-stem] + 甲斐がある
甲斐がある says an effort was worth it: what you put in brought the result you hoped for. The effort is usually a verb in the た-form, and 甲斐があって leads straight into the result.
甲斐 is a noun, so the clause before it modifies it the way any clause modifies a noun, with no particle in between: ×頑張ったの甲斐. After a noun, though, it takes の: どりょく努力のかいがあった甲斐があった.
With the dictionary form, 甲斐がある says something is worth doing at all, before any result is in.
After a ます-stem, 甲斐 reads がい and joins the verb as one noun, usually written in kana: やりがい "a sense of doing something worthwhile", いきがい生きがい "something to live for", おしえ教えがい "worth teaching".
When the effort was wasted, the sentence takes 甲斐がない. The set phrase かい甲斐もなく, "in spite of", is its own grammar point.