Skip to content

Commit 23de798

Browse files
committed
Add Kubernetes service and deployment configurations for voucher service and worker; include Helm chart templates and update README for makefile usage
1 parent 2fbde4d commit 23de798

27 files changed

+1295
-2
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
build:
22
dotnet build
33
start:
4-
dotnet run --project ./src/Genocs.TelegramIntegration.WebApi
4+
dotnet run --project ./src/apps/Genocs.TelegramIntegration.WebApi
55
nuget:
66
nuget pack -NoDefaultExcludes -OutputDirectory nupkgs
77
publish:
@@ -23,4 +23,12 @@ fds: # force rededeploy aws ecs service
2323
gw: # git docker workflow to push docker image to the repository based on the main branch
2424
@echo triggering github workflow to push docker image to container
2525
@echo ensure that you have the gh-cli installed and authenticated.
26-
gh workflow run dockerhub-publish -f push_to_docker=true
26+
gh workflow run dockerhub-publish -f push_to_docker=true
27+
28+
d-build: # docker build images
29+
@echo building docker images
30+
@echo you should have docker installed and running
31+
bash ./src/apps/scripts/build-images.sh
32+
d-push: # docker tag and push images
33+
@echo tag images as latest and publish
34+
bash ./src/apps/scripts/push-images.sh

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,37 @@ You can deploy the application on Kubernetes cluster.
537537
./src/apps/scripts/deploy-k8s.sh
538538
```
539539

540+
### How to use makefile
541+
542+
Prerequisites:
543+
- make
544+
545+
To install make on MacOS you can use brew
546+
547+
``` bash
548+
brew install make
549+
```
550+
551+
To install make on Ubuntu you can use apt
552+
553+
``` bash
554+
sudo apt install make
555+
```
556+
557+
To install make on Windows you can use [choco](https://chocolatey.org/)
558+
559+
``` bash
560+
choco install make
561+
```
562+
563+
Upon installation you can use the makefile to build, run, deploy the application.
564+
565+
``` bash
566+
# Build the solution
567+
make build
568+
```
569+
570+
540571

541572
### Deploy in a cloud instance
542573

src/apps/k8s/helm/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Voucher - Kubernetes Cluster Setup
2+
3+
This folder contains the necessary files to setup a Kubernetes cluster for the Generic service.
4+
5+
The application is composed by a WebApi and a Worker handled by as couple of Docker images.
6+
7+
The voucher-secret.yaml file contains the secrets for the application. The secrets are stored in a Kubernetes Secret object.
8+
9+
The Production secrets are stored in a Azure Key Vault and are retrieved by the application using the Azure Key Vault Provider for Secrets Store CSI Driver.
10+
11+
``` sh
12+
# Create a namespace for the application i
13+
kubectl create namespace utu-taxfree
14+
15+
# Deploy the all the all the components components along with it's secrets
16+
kubectl apply R -f ./voucher-webapi.yaml
17+
kubectl apply R -f ./voucher-secret.yaml
18+
# patch the deployment to use the load balancer
19+
# kubectl patch svc -n utu-taxfree jaeger-simple-query -p '{"spec": {"type": "LoadBalancer"}}'
20+
# az login --tenant 3e106da8-8aaa-441e-8e17-9752767e6585
21+
```
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
4+
metadata:
5+
name: voucher-webapi
6+
namespace: utu-taxfree
7+
labels:
8+
app: voucher-webapi
9+
run: voucher-webapi
10+
11+
spec:
12+
replicas: 1
13+
selector:
14+
matchLabels:
15+
run: voucher-webapi
16+
17+
template:
18+
metadata:
19+
labels:
20+
app: voucher-webapi
21+
run: voucher-webapi
22+
23+
spec:
24+
containers:
25+
- name: voucher-webapi
26+
image: uturegistry.azurecr.io/voucher.webapi
27+
livenessProbe:
28+
httpGet:
29+
path: /hc
30+
port: 80
31+
initialDelaySeconds: 30
32+
periodSeconds: 30
33+
timeoutSeconds: 15
34+
failureThreshold: 10
35+
env:
36+
- name: ASPNETCORE_ENVIRONMENT
37+
value: "Development"
38+
- name: KeyVaultName
39+
value: "UTU-KV-AppSettings-Dev"
40+
- name: KeyVaultUserIdentityId
41+
value: "b1470371-ef6e-42e7-8288-1bb5f61f3728"
42+
- name: Blob__VoucherContainer
43+
value: "dev-vouchers"
44+
- name: Blob__TaxfreeFolder
45+
value: "taxfree"
46+
- name: Blob__ReceiptFolder
47+
value: "receipt"
48+
- name: Blob__MemberPicturesContainer
49+
value: "dev-memberpictures"
50+
- name: ApplicationsInsights__ConnectionString
51+
value: "InstrumentationKey=d7ec8ebc-ba2a-4f7f-90bb-a6ac05e1fe88"
52+
- name: DBSettings__HealthConnectionString
53+
valueFrom:
54+
secretKeyRef:
55+
name: taxfree-app-secret
56+
key: HEALTH_CONNECTION_STRING
57+
- name: DBSettings__ConnectionString
58+
valueFrom:
59+
secretKeyRef:
60+
name: taxfree-app-secret
61+
key: MONGODB_CONNECTION_STRING
62+
- name: DBSettings__Database
63+
value: "UTU-PromotionEngine-Dev"
64+
- name: DBSettings__GenericDB
65+
value: "UTU-Generic-Dev"
66+
- name: JWT__ValidIssuer
67+
value: "https://utuapi-auth-dev.azurewebsites.net"
68+
- name: JWT__ValidAudience
69+
value: "https://utuapi-auth-dev.azurewebsites.net"
70+
- name: JWT__Secret
71+
valueFrom:
72+
secretKeyRef:
73+
name: taxfree-app-secret
74+
key: JWT_SECRET
75+
- name: MassTransitSettings__HostName
76+
valueFrom:
77+
secretKeyRef:
78+
name: taxfree-app-secret
79+
key: RABBITMQ_HOST_NAME
80+
- name: MassTransitSettings__VirtualHost
81+
valueFrom:
82+
secretKeyRef:
83+
name: taxfree-app-secret
84+
key: RABBITMQ_VIRTUAL_HOST
85+
- name: MassTransitSettings__UserName
86+
valueFrom:
87+
secretKeyRef:
88+
name: taxfree-app-secret
89+
key: RABBITMQ_USER_NAME
90+
- name: MassTransitSettings__Password
91+
valueFrom:
92+
secretKeyRef:
93+
name: taxfree-app-secret
94+
key: RABBITMQ_PASSWORD
95+
- name: AzureServiceBusSettings__ConnectionString
96+
valueFrom:
97+
secretKeyRef:
98+
name: taxfree-app-secret
99+
key: AZURE_SERVICE_BUS_CONNECTION_STRING
100+
- name: SendGridSettings__ApiKey
101+
valueFrom:
102+
secretKeyRef:
103+
name: taxfree-app-secret
104+
key: SENDGRID_API_KEY
105+
- name: SendGridSettings__FromEmail
106+
107+
- name: AzureCognitiveServices__Endpoint
108+
value: "https://utu-cognitive-services-dev.cognitiveservices.azure.com"
109+
- name: AzureCognitiveServices__SubscriptionKey
110+
value: "da95a31f4d98448b9d0a605f04b6152b"
111+
- name: AzureCognitiveServices__TaxfreeClassifyUrl
112+
value: "/customvision/v3.0/Prediction/df759587-1b45-4e13-90b6-dc0db8625b7b/classify/iterations/Iteration8/url"
113+
- name: BlobStorageSettings__ConnectionString
114+
valueFrom:
115+
secretKeyRef:
116+
name: taxfree-app-secret
117+
key: BLOB_STORAGE_CONNECTION_STRING
118+
- name: BlobStorageSettings__BaseURI
119+
value: "https://utustorage.blob.core.windows.net"
120+
- name: APIClientSettings__AuthApiUrl
121+
value: "https://utuapi-auth-dev.azurewebsites.net"
122+
- name: APIClientSettings__CMSApiUrl
123+
value: "https://utuapi-cms-dev.azurewebsites.net"
124+
- name: APIClientSettings__ExchangeApiUrl
125+
value: "https://utuapi-exchange-dev.azurewebsites.net"
126+
- name: APIClientSettings__APIKey
127+
valueFrom:
128+
secretKeyRef:
129+
name: taxfree-app-secret
130+
key: UTU_API_KEY
131+
- name: EPPlus__ExcelPackage__LicenseContext
132+
value: "NonCommercial"
133+
- name: utuLogoUrl
134+
value: "https://utuwsimages.blob.core.windows.net/websiteimages/211004%20-%20utu%20logo%20-%20512x512%20JPG.jpg"
135+
- name: VoucherDailyTransactionReportTemplateId
136+
value: "d-de2bde74209241c8b5e9d66b50dc395e"
137+
- name: AllowedHosts
138+
value: "*"
139+
- name: DomainPath
140+
value: "http://utuaksapi-dev.westeurope.cloudapp.azure.com/"
141+
142+
resources:
143+
requests:
144+
cpu: "200m" #20% of a core
145+
memory: "200Mi"
146+
limits:
147+
cpu: "200m" #20% of a core
148+
memory: "200Mi"
149+
imagePullPolicy: Always
150+
151+
restartPolicy: Always
152+
terminationGracePeriodSeconds: 30
153+
dnsPolicy: ClusterFirst
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
4+
metadata:
5+
name: voucher-worker
6+
namespace: utu-taxfree
7+
labels:
8+
app: voucher-worker
9+
run: voucher-worker
10+
11+
spec:
12+
replicas: 1
13+
selector:
14+
matchLabels:
15+
run: voucher-worker
16+
17+
template:
18+
metadata:
19+
labels:
20+
app: voucher-worker
21+
run: voucher-worker
22+
23+
spec:
24+
containers:
25+
- name: voucher-worker
26+
image: uturegistry.azurecr.io/voucher.worker
27+
env:
28+
- name: DOTNET_ENVIRONMENT
29+
value: "Development"
30+
resources:
31+
requests:
32+
cpu: "100m" #10% of a core
33+
memory: "100Mi"
34+
limits:
35+
cpu: "100m" #10% of a core
36+
memory: "100Mi"
37+
imagePullPolicy: Always
38+
39+
restartPolicy: Always
40+
terminationGracePeriodSeconds: 30
41+
dnsPolicy: ClusterFirst
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
kind: Service
3+
4+
metadata:
5+
name: voucher-service
6+
namespace: utu-taxfree
7+
labels:
8+
run: voucher-webapi
9+
10+
spec:
11+
type: ClusterIP
12+
13+
ports:
14+
- protocol: TCP
15+
name: http-port
16+
port: 80
17+
targetPort: 8080
18+
19+
selector:
20+
run: voucher-webapi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: gnxchart
3+
description: A Genocs application Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 1.0.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.0.0"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "gnxchart.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "gnxchart.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "gnxchart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "gnxchart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}

0 commit comments

Comments
 (0)