Mitochondrial function is central to longevity and an imbalance in mitonuclear protein homeostasis activates a protective response called the mitochondrial unfolded protein response (UPRmt). Toxic compounds damaging mitochondria trigger the UPRmt, but at sublethal doses these insults extend lifespan in simple animals like C. elegans. Mitochondria are the main energy suppliers in eukaryotes, but it is not known if diet influences the UPRmt. High dietary glucose reduces lifespan in worms, and we show that high dietary glucose activates the UPRmt to protect against lifespan reduction. While lifelong exposure to glucose reduces lifespan, glucose exposure restricted to developing animals extends lifespan and requires the UPRmt. However, this lifespan extension is abolished by further mitochondrial stress in adult animals. We demonstrate that dietary conditions regulate mitochondrial homeostasis, where induction of the UPRmt during development extends lifespan, but prolonged activation into adulthood reduces lifespan.