Can you set an entire campaign in a dungeon?
Yes, of course.
Gary Gygax developed dungeons of Greyhawk in his numberless campaigns and in the most famous D&D setting, Forgotten Realms, you can find the huge dungeon of Undermountain.
Those are only the most important examples.
Can an entire campaign "function" if set in a dungeon?
Yes, but you must take some decisions.
The dungeon is a mirror of the world and it can't exist without it.
It's not by chance that the famous dungeons of Greyhawk and Undermountain are inside the two great cities of Greyhawk and Waterdeep.
If you want to focus on a dungeon, however, you should avoid great cities around it, to not give distractions to your players.
Create a place in the surroundings where the party can rest, eat, recharge, buy items and sell those found in the explorations.
A small town (1.000-2.000 dwellers) with some inns, temples and merchants is enough.
Project more than one entryway.
Create at least 3, and at least one of them should be hidden or secret.
Use the surface area above the dungeon as an Introductory level: to find new ways in will be a reward and an incentive.
All important dungeons are on more than one level.
Do the same, but avoid excesses.
As a Golden Rule of the Good DM
Too much is an enemy of the just
An adeguate number of levels is around 5.
Connections and sub-levels
Connect every level with its next.
Devise multiple connections between the levels and at least a connection between multiple levels: you'll give more freedom of choice to your players.
Change connections from time to time: stairs, elevators, teleport circles, ropes in a well, and many more others.
Create also sublevels which can be reached only under determinated conditions or after determinated situations: for example a lever pulled in the first level changes the course of a stream in the second and opens the entrance of a sublevel.
At least one of those sublevels should be secret, for the same reasons written above.
Avoid guided routes.
Try to give to your players multiple choices for their paths.
Players shouldn't feel forced in their choices.
I don't like traps a lot .
An average players can easily lessen the chance to trigger a trap.
Should he fail into it, rarely damages cause danger into players unless they are all deadly traps, that is nonsense.
Use traps to increase difficulty encounter level instead; there you can find some examples.
It does make sense that every level should have particular monsters and features.
Put tribes of humanoids (or others) to control one or more levels.
Going deeper in the dungeons increase the difficulty level of encounters and challenges.
Choose a "Lord of the Dungeon", who controls at least an area of the dungeon (maybe the last level) and use it to give to your players a "last challenge".
A dungeon campaign should be for PCs from 1st to 11th-12th level.
Start from the bottom and increase their level to their last epic fight.
Challenge rating and exploration
Don't put a hard encounter in every room.
You only will force your players to stop explorations after 2-3 Rooms to rest and recharge, maybe outside the dungeon.
Settle encounters to allow at least an exploration of 10 Rooms from a rest to another.
Create bare rooms without problems.
Avoid repetitions and too many details: a row of empty rooms is boring while to describe too many details for every room is useless and wastes only resources and time.
Choose a couple of details to let your players say "It's the black brick room" or "It's the persian tapestries room".