k8s-dotnet-microservices-monorepo-saas
k8s-dotnet-microservices-monorepo-saas copied to clipboard
dotnet microservices in monorepo using github actions to deploy to k8s
k8s-dotnet-microservices-monorepo-saas
A work in progress demonstrating
- k8s deployments to digital ocean using helm charts
- microservices using dotnet
- CI-CD using github actions
- monorepo
- to build a demo software as a service application
-
- Sites
- 1.1. Marketing Website Overview
- 1.2. Registration Website Overview
- 1.3. Management Website Overview
- 1.4. Sales Website Overview
- 1.5. Admin Website Overview
-
- Gateways
- 2.1. Sales Gateway
- 2.2. Management Gateway
-
- Microservices
- 3.1. Users Microservice
- 3.2. Stores Microservice
- 3.3. Catalog Microservice
- 3.4. Carts Microservice
- 3.5. Search Microservice
- 3.6. Orders Microservice
Builds
Deployments
Environments
Development
The top level domain is ecommerce-store-builder.dev
Example stores
Custom domain names for example stores
Production
The top level domain is ecommerce-store-builder.com
Example stores
Custom domain names for example stores
Solution Diagrams
Context
client -> ingress -> frontend -> backend -> service
1. Sites
1.1. Marketing Website Overview
1.2. Registration Website Overview
1.3. Management Website Overview
1.4. Sales Website Overview
1.5. Admin Website Overview
2. Gateways
2.1. Sales Gateway
2.2. Management Gateway
3. Microservices
3.1. Accounts Microservice
Use Cases
- Create account
- Add user to account
- Auth user
Publishes
- Account Created
- User Created
Subscribes
- None
3.2. Stores Microservice
Use Cases
- Create store
- Get store
- Get store by domain
- Set store theme
- Set store custom domain
3.1. Users Microservice
API
- Create (userId, email, password) [Anonymous]
- Auth (email, password) [Anonymous]
Application
Domain
- User
Infrastructure
- CurrentSiteContext
- CurrentUserContext
Publishes
- UserCreated
Subscribes
3.2. Stores Microservice
API
- Create (storeId, name) [Anonymous]
- GetById (storeId) [Anonymous]
- GetByDomain (domain) [Anonymous]
- SetTheme (storeId, theme) [Owner]
- SetCustomDomain (storeId, domain) [Owner]
- List () [Admin]
Application
Domain
- Cart
- CartItem
Infrastructure
Publishes
- StoreCreated
- StoreUpdated
Subscribes
3.3. Products Microservice
3.4. Carts Microservice
3.5. Search Microservice
3.6. Media Microservice
Running in docker
- infra
docker-compose -f docker-compose-infra.yaml up
- platform
docker-compose -f docker-compose.yaml build
docker-compose -f docker-compose.yaml -f docker-compose.override.yaml up
docker-compose -f docker-compose.yaml down
Development
Host file setup
127.0.0.1 marketing.saas.io
127.0.0.1 registration.saas.io
127.0.0.1 shopping.saas.io
127.0.0.1 management.saas.io
127.0.0.1 admin.saas.io
127.0.0.1 example1.saas.io
127.0.0.1 example2.saas.io
127.0.0.1 example3.saas.io
127.0.0.1 example1.io
127.0.0.1 example2.io
127.0.0.1 example3.io
Port registry
FrontEnds
- marketing 8010
- registration 8020
- shopping 8030
- management 8040
- admin 8050
Gateways
- marketing 7010
- registration 7020
- shopping 7030
- management 7040
- admin 7050
Backends
- registration 6020
- shopping 6030
Services
- catalog 5010
- carts 5020
- media 5030
- search 5040
- stores 5050
- accounts 5060
Build
Github Actions
- Setup Secrets
-
DIGITALOCEAN_ACCESS_TOKEN
-
REGISTRY_ENDPOINT
in the formghcr.io/peterkneale/k8s-dotnet-microservices-monorepo-saas
-
REGISTRY_HOST
in the formghcr.io
-
Release
Setup
- Set environment variables
export GITHUB_USERNAME=peterkneale
export GITHUB_TOKEN=XXXXXXXXXXXXXX
export DIGITALOCEAN_TOKEN=XXXXXXXXXXXXXX
export REGISTRY_HOST=ghcr.io
export REGISTRY_ENDPOINT=ghcr.io/peterkneale/k8s-dotnet-microservices-monorepo-saas
export TAG=latest
echo $GITHUB_TOKEN | docker login $REGISTRY_HOST -u $GITHUB_USERNAME --password-stdin
echo $DIGITALOCEAN_TOKEN | doctl auth init --context saas
K8s
Digital Ocean
- Setup cluster in Digital Ocean
- Install add-ons
NGINX Ingress Controller
andCert-Manager
- run
k8s-install.sh
in/deploy/infra/digitalocean
Accessing cluster resources
Accessing a resource in the k8s cluster can be performed by using kubectl's port forwarding feature Forwarding the local port 8080 to the below services will make them available on http://localhost:8080
-
Dashboard
kubectl -n default port-forward svc/infra-dashboard-kubernetes-dashboard 8443:443 kubectl describe secret -n kube-system | grep deployment -A 12
-
A service
kubectl port-forward --namespace development svc/service-accounts-saas 8080:80
$ curl localhost:8080/health/alive Healthy