You can keep a duck as a pet in the city - if your city statues allow. In some cities, you cannot keep any wild fowl whatsoever, unless you get a license. You certainly cannot keep either a flock nor brace, nor raft, nor paddling nor team of ducks. In many western cities, however, to keep a single duck as a pet is just ... ducky!
Ducks are not strict vegetarians, but they do well on a diet of grains and green plants. In a pond, they will dive to the bottom and wrench small, tender plants from the muddy bottoms and come up to consume them. If the occasional invertebrate gets in the way or tangled in the munchables, then down the gullet it goes as well. The muddy bottom actually helps them supply sand, pebbles or gravel to the gizzard for grinding stones, which helps pulverize their food. They can eat berries or nuts and your favorite flower bulbs, so make sure your flower garden is duck-proof!
If you are planning to keep your pet duck inside most of the time, then you can get a variety of grains from a feed store. You might also include vitamins in either a powdered or liquid form and spread them occasionally on their feed. A good veterinarian should be able to help you figure out an appropriate diet. An important part of raising a duck is to provide constant water, deep enough so they can submerge their heads in order to clean their beaks and eyes. You can raise your duck without swimming-depth water, but not without head-dunking depth water!
As for duck treats, you can treat with carrots, lettuce, most vegetables and even tomatoes. Most human snacks are deadly to ducks and will cost you in vet bills down the road and your duck extreme discomfort.
Ducks do lay very large eggs. If your personal diet includes eggs, then you can consume the eggs laid by your pet. You should plan on sharing the egg with someone, because the eggs of a duck are easily twice the size of a large chicken egg. Some people swear they can tell the difference between the taste of a duck's egg and that of a chicken, but I find it quite similar. I had an occasion several years ago to be in receipt of a supply of duck eggs from a university duck research center in Arkansas. I cooked and baked with them and we were completely pleased with the results.
Ducks make good intruder alert systems and will quack at the unexpected guest. However, be advised that ducks can be very territorial and deliver a painful bite if crossed. My grandmother was chased by the ducks in their family coop, but those ducks were not pets. She swore certain ducks knew her by sight and planned attacks in advance of her coming to collect eggs. She would snap a towel at them to keep them at bay, but the best defense was retreat.
You can make a nest box for your pet duck out of any materials lying about your home. You won't want to use lead painted wood, but any untreated lumber should be fine. Make it about a foot square, six inches deep and line it with straw. If you don't provide a nest, they'll likely lay their eggs any old place in your yard. It is disconcerting to step on a duck's egg.
Ducks have interesting personalities and habits. After you have bonded and trained your pet duck, you might be able to put a collar on it and walk it to a local pond for a bit of a swim. Make sure it comes to you when you call, however, or you may lose your pet to the call of the wild.