This currently targets dotnet 9 and was created using VS2022 Community. It uses dotnet secret manager for passwords instead of putting them in appsettings. It could be adapted to use a keyvault or some other external provider. Depending on what type of database you want to use there is an appsetting for either postgres or mongo. Dockerfile is provided to build a conatinerized version of the app for use in a Kubernetes cluster. The mongo db used locally was a containerized version. Postgres is version 15, but shouldn't be an issue for other recent versions. The schema is RESTFUL.
CREATE TABLE IF NOT EXISTS "RESTFUL".items
(
"Id" uuid NOT NULL,
"Name" character varying(200) COLLATE pg_catalog."default" NOT NULL,
"Price" numeric NOT NULL,
"CreatedDate" date NOT NULL,
CONSTRAINT "Item_pkey" PRIMARY KEY ("Id")
)
(secrets can typically be found here %APPDATA%\Microsoft\UserSecrets<user_secrets_id>\secrets.json)
dotnet user-secrets init
dotnet user-secrets set MongoDBSettings:Password somepassword
dotnet user-secrets set PGSQLSettings:Password somepassword
dotnet user-secrets remove PGSQLSettings:Password
dotnet ef add migration {name of migration}
dotnet ef database update
docker build -t yourdockerhub/restful:v1.0.0 .
docker network create restfulnet
docker run -d --rm --name mongo -p 27017:27017 -v mongodbdata:/data/db -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=password --network=restfulnet mongo
docker run -it --rm -p 2800:80 -e MongoDBSettings:Host=mongo -e MongoDBSettings:Password=password --network=restfulnet restful:v1.0.0
docker run -it --rm -p 2800:80 -e PGSQLSettings:Host=somenetworkwithyourpostgresdb -e PGSQLSettings:Password=password --network=restfulnet restful:v1.0.0
az aks get-credentials -n dev --context dev --resource-group your-group
kubectl create secret generic restful-secrets --from-literal=mongodb-password='somepassword'
kubectl apply -f mongodb.yml
kubectl apply -f restful.yml
kubectl get po