Skip to content

Commit 1c9595d

Browse files
committed
Add helm charts .helmignore and service.yml files, update resource limits and requests
1 parent 4ec6f72 commit 1c9595d

21 files changed

+632
-71
lines changed

.github/workflows/cd.yml

+33-3
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,40 @@ jobs:
8686
cluster-name: ${{ env.CLUSTER_NAME }}
8787
admin: 'false'
8888
use-kubelogin: 'true'
89+
90+
- name: Install Helm
91+
run: |
92+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
93+
chmod 700 get_helm.sh
94+
./get_helm.sh
8995
90-
# Deploys application based on given manifest file
9196
- name: Deploy to Kubernetes [PRODUCTION ENVIRONMENT]
9297
run: |
93-
kubectl apply -f deployments/
98+
# Get the commit message of the commit that triggered the workflow
99+
COMMIT_MESSAGE=$(git log --format=%B -n 1 ${{ github.event.after }})
100+
101+
# Check if the app deployment exists
102+
if kubectl get deployments app-release; then
103+
# If the commit message starts with [v1], it's an update for v1
104+
if [[ "$COMMIT_MESSAGE" == \[v1\]* ]]; then
105+
echo "Update is for v1. Not setting v2.image.tag."
106+
# Update the app without changing the v2 image
107+
helm upgrade --install app-release ./my-chart
108+
else
109+
# If the commit message does not start with [v1], it's an update for v2
110+
echo "Update is for v2. Setting v2.image.tag to: ${{ inputs.image_tag }}."
111+
# Update the app and change the v2 image to inputs.image_tag
112+
helm upgrade --install app-release ./my-chart --set v2.image.tag=${{ inputs.image_tag }}
113+
fi
114+
else
115+
# If the app deployment does not exist
116+
echo "App deployment does not exist. Setting v2.image.tag to: ${{ inputs.image_tag }}."
117+
# Set v2.image.tag to inputs.image_tag regardless of the commit message
118+
helm upgrade --install app-release ./my-chart --set v2.image.tag=${{ inputs.image_tag }}
119+
fi
120+
121+
# Wait for 30 seconds
94122
sleep 30
95-
kubectl get deployments
123+
124+
# Get the status of the deployments
125+
kubectl get deployments

README.md

+48-21
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,54 @@ stateDiagram
6565
Deploy --> [ProdInstance1]: Blue
6666
Deploy --> [ProdInstance2]: Green
6767
```
68+
## Blue-Green Deployment Strategy Diagram
69+
70+
```mermaid
71+
sequenceDiagram
72+
participant C as Commit
73+
participant G as GitHub Actions
74+
participant H as Helm
75+
participant K as Kubernetes
76+
C->>G: Developer pushes a commit
77+
G->>G: GitHub Actions extracts the commit message
78+
Note over G: GitHub Actions checks if the commit message starts with [v1]
79+
alt Commit message starts with [v1]
80+
G->>H: GitHub Actions tells Helm to update the app without changing the v2 image
81+
Note over G: The v2 image remains the same
82+
else Commit message does not start with [v1]
83+
G->>H: GitHub Actions tells Helm to update the app and change the v2 image
84+
Note over G: The v2 image is updated to the new version
85+
end
86+
H->>K: Helm deploys or updates the Kubernetes resources
87+
G->>K: GitHub Actions checks the status of the deployments
88+
```
6889
## App deployment flow - in this diagram
69-
- User sends a request to the Load Balancer
70-
- Load Balancer routes the request to the Kubernetes Service
71-
- Kubernetes Service routes the request to the Spring Boot App
72-
- Spring Boot App queries the Database
73-
- Database returns data to the Spring Boot App
74-
- Spring Boot App checks the Feature Flag
75-
- Feature Flag returns the flag status to the Spring Boot App
76-
- Spring Boot App checks the Redis Cache
77-
- Redis Cache returns the session data to the Spring Boot App
78-
- Spring Boot App returns the response to the User
79-
- App Startup deploys the Database
80-
- Canary Deployment spins up new pods
81-
- Rollback triggers a Canary Deployment
82-
- Canary Deployment deploys the previous stable Docker image
83-
- Canary Deployment reverts database changes
84-
- Promote deploys to all pods
85-
- Monitoring alerts the Ops Team
86-
- Ops Team fixes issues
87-
- Rollback/Canary Deployment deploys the fix
88-
- New Pods verifies the fix
89-
- Monitoring verifies the fix
90+
## User Request Flow
91+
1. User sends a request to the Load Balancer.
92+
2. Load Balancer routes the request to the Kubernetes Service.
93+
3. Kubernetes Service routes the request to the Spring Boot App.
94+
4. Spring Boot App queries the Database.
95+
5. Database returns data to the Spring Boot App.
96+
6. Spring Boot App checks the Feature Flag.
97+
7. Feature Flag returns the flag status to the Spring Boot App.
98+
8. Spring Boot App checks the Redis Cache.
99+
9. Redis Cache returns the session data to the Spring Boot App.
100+
10. Spring Boot App returns the response to the User.
101+
102+
## Deployment Process
103+
1. App Startup deploys the Database.
104+
2. Canary Deployment spins up new pods.
105+
3. Rollback triggers a Canary Deployment.
106+
4. Canary Deployment deploys the previous stable Docker image.
107+
5. Canary Deployment reverts database changes.
108+
6. Promote deploys to all pods.
109+
110+
## Monitoring and Issue Resolution
111+
1. Monitoring alerts the Ops Team.
112+
2. Ops Team fixes issues.
113+
3. Rollback/Canary Deployment deploys the fix.
114+
4. New Pods verifies the fix.
115+
5. Monitoring verifies the fix.
90116

91117
```mermaid
92118
graph LR
@@ -130,6 +156,7 @@ graph LR
130156
style R fill:#cf6,stroke:#333,stroke-width:2px
131157
style S fill:#6cf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5
132158
```
159+
133160
## GitFlow Diagram
134161
```mermaid
135162
graph TB

build_and_run_app.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# !/bin/bash
2+
if [ -z "$1" ]
3+
then
4+
SEARCH_FEATURE=""
5+
else
6+
SEARCH_FEATURE="-DenableSearchFeature=$1"
7+
fi
8+
29
cleanup() {
310
docker stop redis_container > /dev/null 2>&1 || true
411
docker rm redis_container > /dev/null 2>&1 || true
@@ -11,4 +18,4 @@ trap cleanup EXIT
1118
set -e # Exit immediately if a command exits with a non-zero status.
1219
mvn clean package -Dmaven.test.skip=true
1320
docker run -d -p 6379:6379 --name redis_container redis
14-
java -jar target/salesmanager-*-SNAPSHOT.jar --spring.redis.host=localhost --spring.redis.port=6379 --spring.redis.mode=standalone --server.port=8086 --spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
21+
java $SEARCH_FEATURE -jar target/salesmanager-*-SNAPSHOT.jar --spring.redis.host=localhost --spring.redis.port=6379 --spring.redis.mode=standalone --server.port=8086 --spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

deployments/postgres_db-deployment.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ spec:
7878
volumeMounts:
7979
- mountPath: /var/lib/postgresql/data
8080
name: postgredb
81+
resources:
82+
limits:
83+
cpu: "1"
84+
memory: "1Gi"
85+
requests:
86+
cpu: "100m"
87+
memory: "512Mi"
8188
volumes:
8289
- name: postgredb
8390
# persistentVolumeClaim:

deployments/redis_db-deployment.yaml

+16-10
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ spec:
3232
labels:
3333
app: redis-database
3434
spec:
35-
containers:
36-
- name: redis-database-container
37-
image: redis:latest
38-
imagePullPolicy: "IfNotPresent"
39-
ports:
40-
- containerPort: 6379
41-
envFrom:
42-
- configMapRef:
43-
name: redis-config
44-
---
35+
containers:
36+
- name: redis-database-container
37+
image: redis:latest
38+
imagePullPolicy: "IfNotPresent"
39+
ports:
40+
- containerPort: 6379
41+
envFrom:
42+
- configMapRef:
43+
name: redis-config
44+
resources:
45+
limits:
46+
cpu: "0.5"
47+
memory: "512Mi"
48+
requests:
49+
cpu: "0.1"
50+
memory: "256Mi"

deployments/spring-app-deployment-v1.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,12 @@ spec:
2929
value: changelog_version-3.3.xml
3030
- name: REDIS_HOST
3131
value: redis-database-service
32+
resources:
33+
limits:
34+
cpu: "1"
35+
memory: "512Mi"
36+
requests:
37+
cpu: "0.25"
38+
memory: "128Mi"
3239
imagePullSecrets:
3340
- name: your-registry-secret

deployments/spring-app-deployment-v2.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,12 @@ spec:
2929
value: changelog_version-3.3.xml
3030
- name: REDIS_HOST
3131
value: redis-database-service
32+
resources:
33+
limits:
34+
cpu: "1"
35+
memory: "512Mi"
36+
requests:
37+
cpu: "0.25"
38+
memory: "128Mi"
3239
imagePullSecrets:
3340
- name: your-registry-secret

my-chart/.helmignore

+23
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/

my-chart/Chart.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v2
2+
name: my-chart
3+
description: A Helm chart for Kubernetes
4+
# A chart can be either an 'application' or a 'library' chart.
5+
#
6+
# Application charts are a collection of templates that can be packaged into versioned archives
7+
# to be deployed.
8+
#
9+
# Library charts provide useful utilities or functions for the chart developer. They're included as
10+
# a dependency of application charts to inject those utilities and functions into the rendering
11+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
12+
type: application
13+
# This is the chart version. This version number should be incremented each time you make changes
14+
# to the chart and its templates, including the app version.
15+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
16+
version: 0.1.0
17+
# This is the version number of the application being deployed. This version number should be
18+
# incremented each time you make changes to the application. Versions are not expected to
19+
# follow Semantic Versioning. They should reflect the version the application is using.
20+
# It is recommended to use it with quotes.
21+
appVersion: "0.1.0"

my-chart/templates/_helpers.tpl

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "my-chart.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "my-chart.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "my-chart.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "my-chart.labels" -}}
37+
helm.sh/chart: {{ include "my-chart.chart" . }}
38+
{{ include "my-chart.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "my-chart.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "my-chart.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "my-chart.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "my-chart.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

0 commit comments

Comments
 (0)