The Gemara (Shabbat 153a) records Rabbi Eliezer's teaching — "repent one day before your death" — and explains that since one never knows when that day will be, a person should spend their entire life in a state of readiness, drawing support from the pasuk in Kohelet that one must always be prepared.
Sha'arei Teshuvah 2:9 makes the end-of-life application explicit: one is obligated to reflect on their end when old age arrives, and — certainly if they failed to do so in youth — to abandon bodily desires and set their soul in order as their time draws near.
The obligation to care for one's health is grounded in the verse "and he shall surely heal" (Duties of the Heart, Fourth Treatise on Trust 4:37), from which that work derives that a person must actively pursue the maintenance of health and the repulsion of illness by natural means, while trusting that those means are only effective by the Creator's permission.
Duties of the Heart, Fourth Treatise on Trust 4:31 extends this framework to all dimensions of wellbeing — health, food, clothing, shelter, and good character — comparing the obligation to pursue them to a farmer who must plow, clear, sow, and irrigate, while trusting God for the increase.
Undergirding all of this, the pasuk in Devarim (Devarim 32:29) declares that wisdom consists precisely in gaining insight into one's future end, and Pirkei Avot 4:16 counsels that one must prepare oneself in this world — the vestibule — in order to enter the world to come.