When you get married, is it possible to enter into a contract renouncing both parties' right to a divorce? If that is not possible how much can you limit the right to a divorce with a contract or something similar?
When you get married is possible to have contract renouncing both parties right to a divorce.
No. That clause would be redundant, materially indistinguishable from breach of contract, and otherwise unenforceable.
It is redundant because the legal definition of Marriage (Black's Law Dictionary) states that it is "A contract, according to the form prescribed by law, by which a man and woman [...] mutually engage with each other to live their whole lives together in the state of union which ought to exist between a husband and a wife". Thus, the perpetuity as expressed in the term whole lives preempts the conceiving of an eventual separation.
Insofar as marriage is legally cognizable as a contract (see legal definition), it might specify or imply remedies in the event that one or both spouses decide(s) that substance of marital relationship no longer exists; that is, in the event that a breach of that contract occurs. A court may order to the breaching spouse performance of certain acts (for example, alimony) in accordance to statutory law or common law. However, a prohibition to divorce goes beyond the scope of what is legally permissible.
The U.S. Supreme Court in Roberts v. United States Jaycees, 468 U.S. 609, 617-618 (1984) helps explaining why a prohibition to divorce would be unenforceable:
"In one line of decisions, the Court has concluded that choices to enter into and maintain certain intimate human relationships must be secured against undue intrusion by the State because of the role of such relationships in safeguarding the individual freedom that is central to our constitutional scheme. In this respect, freedom of association receives protection as a fundamental element of personal liberty."
If that is not possible how much can you limit the right to a divorce with a contract or something similar?
There is no possible limit or requisite duration of a marriage, as that would inherently infringe a person's fundamental element of personal liberty mentioned in the Roberts case.
In New York, at least, the answer would be no. There are several cases directly addressing no-divorce clauses, and each one I've found has voided them as "unconscionable" or "contrary to public policy."
In Filstein v. Bromberg, 36 Misc. 3d 404, 944 N.Y.S.2d 692 (Sup. Ct. 2012), the New York Supreme Court invalidated a clause prohibiting divorce before the couple sold their marital home because it could render the marriage "interminable depending on the interest and proclivities of New York City apartment buyers." The court said it did not matter that the clause was a condition of the husband entering into the marriage, nor that divorce is not an absolute right: "The clause may not be the only obstacle that exists between the parties and a divorce ... but it is an exceedingly burdensome, and thus impermissible, obstacle."
In another case, P.B. v. L.B., 19 Misc. 3d 186, 855 N.Y.S.2d 836 (Sup. Ct. 2008), the court rejected an agreement "that the husband shall not pursue a divorce against the wife for a period of five years from the signing of this agreement except by prior written consent of the wife.” The court took exception for several reasons, including that the clause was not reciprocal, that it bars divorce on any grounds:
There can be no doubt that a provision in a separation agreement which attempts to frustrate the right of a party to seek a divorce, either using the agreement as its basis or otherwise, is against the state's clearly articulated public policy of allowing parties to seek an end to “dead marriages” that are declared to be over.
And in Corso v. Corso, 21 Misc. 3d 1102(A), 873 N.Y.S.2d 232 (Sup. Ct. 2008), the court said that an agreement "to preclude either party from filing for divorce for five years" was "entirely improper": "Since the Agreement purports to limit the parties' ability to file for divorce, it is void as against public policy."
Again, these are all New York cases, but they are premised in large part on the state's adoption of no-fault divorce, which would pretty easily allow a good argument that they should be followed in other states with a similar scheme, which is pretty much all of them at this point.
Every state in the US has laws allowing and specifying the procedures for marital dissolution. Any contract has to be consistent with the law: you can't write a contract that nullifies / contradicts state law. Three states have a special kind of marriage known as a "covenant marriage", where divorce is made more difficult.