Less than three years ago, before 49ers rookie defensive back D.J. Reed was living out his dream, he was living in a two-bedroom apartment he shared with seven Cerritos College teammates in Norwalk.

He’d landed at the junior college, located about 13 miles from Disneyland, because his mom, Linda, couldn’t afford a second year at Fresno State. And he’d gone to Fresno State as a full-tuition-paying walk-on because no colleges, not even Division II schools, had offered him a scholarship after his senior season at Independence-Bakersfield.

Reed, the cash-strapped Division I reject, slept on the floor of that crammed apartment because he didn’t pay rent, and got by on a diet heavy on $5 pepperoni pizzas from the nearby 7-Eleven.

At least he did on good days.

“Before we played Hancock (College), I didn’t eat,” Reed said. “It was like a four-hour drive over there and I didn’t have anything for breakfast. I don’t think I played terrible, but I just remember having no energy. It was all very humbling.”

Reed has overcome astounding odds, becoming an All-American at Kansas State and a fifth-round draft pick, because he’s stayed hungry.

On Thursday, Reed made his NFL exhibition debut by lining up as the 49ers’ first-string nickel cornerback (a fifth defensive back) in their 24-21 win over the Cowboys at Levi’s Stadium. Reed started because of an injury to K’Waun Williams, but the late-round pick — who also is playing free safety — has made it clear a lack of size (5-foot-9, 188 pounds) or blistering speed won’t prevent him from making the 53-man roster.

The 49ers recently released another installment of their documentary series detailing training camp, and a clip showed general manager John Lynch reviewing video of Reed in practice.

“Good rep by 40,” Lynch said, referring to Reed’s jersey number. “The thing I like about 40 is he will finish every time.”

Lynch finished with this: “He’s made of the right stuff, man.”

Defensive coordinator Robert Saleh has termed Reed “relentless,” hailed the way he “fights his tail off” and praised him for “taking this opportunity and absolutely running with it.” And vice president of player personnel Adam Peters is wowed at Reed’s resolve in the face of rejection.

“He’s a guy that bet on himself,” Peters said. “He said, ‘I’m better than this. And I’m going to prove to everybody that I’m better than this.’ And he worked his ass off and he did it.”

How did Reed do it? He credits his mom for providing the example of faith and strength in the face of adversity.

In 2008, when D.J. was in seventh grade, Linda Reed learned she had congenital heart disease. Six months later, she was diagnosed with Stage 2 breast cancer. During this time, she divorced her husband, Dennis, who now lives in Waterloo, Iowa.

When told of her heart condition, Linda says she calmly explained to doctors that she couldn’t be hospitalized because she had kids to raise. And when she was enduring chemotherapy, she would drag herself out of bed in the late afternoon, just before her children got home, and hope her smile and false energy would allay their fears. D.J. has an older sister, Flo, 34, and younger brother, Tyson, 20.

“They would always say, ‘Mom, you don’t look so good; why don’t you lay down?’” Linda said, laughing, “I’d say, ‘OK, I think I will.’ They had no idea I had just gotten up after spending all day in bed.”

Linda was declared cancer-free after seven months of chemotherapy and seven weeks of radiation. She now visits a cardiologist every six months and an oncologist yearly. In addition to working as a program coordinator for Kern County for 31 years, she has worked for Macy’s and Big Lots, and as a manicurist and car saleswoman to make ends meet.

“Life is going to be what it is,” she said. “You will have highs and you will have lows, but what separates people is the determination to survive and get through it. And that’s what we’ve done. We’ve been survivors all our lives, and our faith in God is our foundation: We believe.”

His mom’s work ethic inspired her middle child. In high school, D.J., desperate to bulk up his slight frame, would sometimes get up in the middle of the night to work out. He’d attack the chin-up bar in his room and hit the floor for push-ups and sit-ups before returning to bed.

And his mom’s faith in the midst of her successful cancer fight gave him the belief that has helped him bust through a series of shut doors. D.J. recalls his mom praising God and clutching her Bible in her lowest moments.

Part of Reed’s Twitter bio reads “God first #induetime.”

“It all came from watching her and praying for her,” Reed said. “When she was diagnosed, I constantly prayed for her to live and, when she made it, it gave me the mind-set God is real. That showed me from an early age that God hears me.”

Reed ignored those who advised him to play at Bakersfield College after high school, because he believed he was Division I material. He was confident Fresno State coaches would recognize his ability after a redshirt walk-on season.

But no scholarship materialized. Fresno State head coach Tim DeRuyter, now Cal’s defensive coordinator, was taken by Reed’s intangibles, but the height-challenged cornerback arrived on campus weighing about 160 pounds and had average speed.

In a meeting after Reed’s first season, DeRuyter told him he eventually would earn a scholarship, but an offer wasn’t imminent. Reed knew his mom had taken out a significant loan for him to attend Fresno State, and couldn’t afford a another year. He was forced to leave.

“You see so many of these guys that are similar to him that try to play over their ability and it’s rare that a guy like D.J. actually makes it to the NFL,” DeRuyter said. “For most of those guys, it doesn’t pan out. They get to that level to where their ability tops out and they can’t overcome that lack of size, that lack of speed, to be able to compete at that elite level.

“He’s one of those rare guys that made it. ... It’s just a great testament to him that he was able to get drafted in the fifth round because of who he is, and not necessarily what he measures at.”

It’s also a testament to Reed that DeRuyter granted a reporter’s interview request to discuss Reed; most coaches don’t speak, at length, about walk-ons who leave their programs and become NFL draft picks.

DeRuyter talked about his mistake because of his respect for Reed. And the head coaches Reed had after he left Fresno were similarly smitten.

At Cerritos, Frank Mazzotta, who recently retired after 40 years as the Falcons’ head coach, was not aware of all the specifics of Reed’s lone season at the school. That is, he didn’t know he was arriving at practice after sleeping on a floor, or relying on the kindness of his teammate, safety Eli Walker, who used food stamps to supply them with breakfast staples: frozen waffles and peanut butter.

Those details didn’t surprise him. Mazzotta relied on local players, and says those who arrived from out of the area needed to have grit to make it. He terms Reed “as tough as they come.”

“We have those kids come in occasionally, but they have to find their own way as far as where to live and how to make it work,” Mazzotta said. “We’re not going to find them an apartment or roommates. And when they survive that, that’s kind of a testament to how tough they are.”

After his season at Cerritos, Reed received a scholarship offer from Indiana State, an FBS program in the Missouri Valley Football Conference. Reed declined what was then his lone offer because he remained convinced he was D-I material.

He was right. A week later, he received an offer from Kansas State.

“I was like, I’m a 5-9 corner, so I want to go in a conference where I’m playing elite competition,” Reed said. “So when I get to the NFL combine, they can’t say ‘Oh, he’s too small; he didn’t play against anybody.’ (Kansas State was) the first big school to offer me, and they were in the Big 12. So if you’re good, it’s going to be obvious that you’re good. And if you’re not, it’s going to show that, too.”

Reed proved he was quite good after getting his long-awaited chance.

In two seasons at Kansas State, he was a two-time All-Big 12 pick who ranks second in school history in kickoff-return average (34.2 yards) and sixth in punt-return average (14.9). In 2016, he was the Big 12 Defensive Newcomer of the Year. In 2017, he was a second-team Walter Camp All-American.

Kansas State head coach Bill Snyder, 78, a member of the College Football Hall of Fame, says Reed has a unique burst that allowed him to excel on kick returns and in coverage. But Snyder doesn’t spend much time talking about Reed’s football ability.

“There will be more talented people around here than D.J.,” Snyder said, “but it’s all his other qualities that will keep him in the NFL. He’ll have longevity in the league, I’m quite certain.”

Snyder noted he’d recently received a thank-you letter from Reed. The former team captain told Snyder he cherished the coach’s “16 goals for success.” One goal — which deals with perseverance — is inscribed on a wristband Reed still wears.

“‘The goal that stands out to me is never give up,’” Snyder says, reading from Reed’s letter. “‘… You’ve molded me into the man I’ve become. Thank you for giving me the platform to play at the Division I level.’”

Said Snyder: “D.J. is just that type of young man. He’s just a guy that has that value system in place and is accustomed to saying thank you.”

Reed’s appreciation is at least partly borne out by his background.

When he first arrived at Kansas State, for example, he was shocked that some of his on-scholarship peers found fault with the meals provided.

“There were guys complaining and I’d be like, ‘You guys are tripping, man,’” Reed said. “I’m going to take advantage of all of this, and I’m very appreciative of food.”

Reed took such advantage of his Division I opportunity that he could declare for the NFL draft after his junior season. He wrestled with the decision, but ultimately left KSU so he could provide financial support for his mom, who now works only one job.

And Reed, who signed a four-year, $2.77 million contract, is working at his dream job less than three years after his dreams came when he slept on a floor at Cerritos.

So how did he make it from that crammed apartment to the NFL?

He’s made of the right stuff, man.

Eric Branch is a San Francisco Chronicle staff writer. Email: ebranch@sfchronicle.com Twitter: @Eric_Branch