Set the Instant Pot to sauté mode. Add the ground beef, diced onion, and minced garlic. Cook until the beef is browned and the onions are translucent, about 5-7 minutes. Drain excess fat if necessary.
Add the crushed tomatoes, tomato sauce, water, Italian seasoning, salt, black pepper, and red pepper flakes (if using) to the pot. Stir to combine.
Break the spaghetti in half and gently push it into the sauce mixture, ensuring it is mostly submerged. Do not stir.
Close the lid of the Instant Pot and set the valve to sealing. Cook on high pressure for 8 minutes.
Once the cooking time is complete, carefully perform a quick release of the pressure. Open the lid and stir the spaghetti well to combine with the sauce.
Serve hot, topped with grated Parmesan cheese and fresh basil leaves if desired.