Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .infrastructure/helm-chart/todoapp/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
8 changes: 8 additions & 0 deletions .infrastructure/helm-chart/todoapp/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v2
name: todoapp
description: A Helm chart for Kubernetes
type: application
version: 0.1.1
appVersion: "1.16.0"
dependencies:
- name: mysql
23 changes: 23 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: mysql
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "1.16.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql
namespace: {{ .Values.mysql.namespace }}
labels:
app: mysql
data:
init.sql: |
GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'%';
USE app_db;
CREATE TABLE counter (
id INT AUTO_INCREMENT PRIMARY KEY,
value INT
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.mysql.namespace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: mysql-secrets
namespace: {{ .Values.mysql.namespace }}
type: Opaque
data:
{{- range $key, $value := .Values.mysql.secrets }}
{{ $key }}: {{ $value }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Headless service for stable DNS entries of StatefulSet members.
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: {{ .Values.mysql.namespace }}
spec:
selector:
app: mysql
ports:
- name: mysql
port: 3306
clusterIP: None

# pod-name.service-name.namespace.svc.cluster.local
# pod-name.service-name
# mysql-0.mysql.mysql.svc.cluster.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: {{ .Values.mysql.namespace }}
spec:
selector:
matchLabels:
app: mysql
replicas: {{ .Values.mysql.dbReplicas }}
serviceName: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: {{ .Values.mysql.image.repo }}:{{ .Values.mysql.image.tag }}
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secrets
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-secrets
key: MYSQL_USER
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secrets
key: MYSQL_PASSWORD
- name: MYSQL_DATABASE
value: app_db
ports:
- name: mysql
containerPort: 3306
volumeMounts:
- name: data
mountPath: /var/lib/mysql
subPath: mysql
- name: config-map
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
cpu: {{ .Values.mysql.resources.requests.cpu }}
memory: {{ .Values.mysql.resources.requests.memory }}
livenessProbe:
exec:
command: ["mysqladmin", "ping"]
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
readinessProbe:
exec:
command: ["mysqladmin", "ping"]
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1
volumes:
- name: config-map
configMap:
name: mysql
tolerations:
- key: {{ .Values.mysql.tolerations.key }}
operator: "Equal"
value: {{ .Values.mysql.tolerations.value }}
effect: "NoSchedule"
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: {{ .Values.mysql.affinity.podaffinity.key }}
operator: In
values:
- {{ .Values.mysql.affinity.podaffinity.value }}
topologyKey: "kubernetes.io/hostname"
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.mysql.affinity.nodeaffinity.key }}
operator: In
values:
- {{ .Values.mysql.affinity.nodeaffinity.value }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: {{ .Values.mysql.VolumeClaim }}
32 changes: 32 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
mysql:
namespace: mysql

image:
repo: mysql
tag: 8.0

dbReplicas: 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check name current value


resources:
requests:
cpu: 500m
memory: 1Gi

secrets:
MYSQL_ROOT_PASSWORD: "MTIzNA==" # Base64 encoding for "1234"
MYSQL_USER: "YXBwX3VzZXI=" # Base64 encoding for "app_user"
MYSQL_PASSWORD: "MTIzNA==" # Base64 encoding for "1234"

VolumeClaim: 2Gi

tolerations:
key: "app"
value: "mysql"
Comment on lines +22 to +24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add operator and effect for this part


affinity:
podaffinity:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add operator here

key: "app"
value: "mysql"
nodeaffinity:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same too

key: "app"
value: "mysql"
13 changes: 13 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/clusterIp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: todoapp-service
namespace: {{ .Values.todoapp.namespace }}
spec:
type: ClusterIP
selector:
app: todoapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
7 changes: 7 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/configMap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: {{ .Values.todoapp.namespace }}
data:
PYTHONUNBUFFERED: "1"
86 changes: 86 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: todoapp
namespace: {{ .Values.todoapp.namespace }}
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: {{ .Values.todoapp.RollUpdParam.maxSurge }}
maxUnavailable: {{ .Values.todoapp.RollUpdParam.maxUnavailable }}
selector:
matchLabels:
app: todoapp
template:
metadata:
labels:
app: todoapp
spec:
serviceAccountName: {{ .Values.todoapp.RBACService.name }}
containers:
- name: todoapp
image: {{ .Values.todoapp.image.repo }}:{{ .Values.todoapp.image.tag }}
volumeMounts:
- name: data
mountPath: /app/data
- name: app-secrets-volume
mountPath: "/app/secrets"
readOnly: true
- name: app-config-volume
mountPath: "/app/configs"
readOnly: true
resources:
requests:
memory: {{ .Values.todoapp.resources.requests.memory }}
cpu: {{ .Values.todoapp.resources.requests.cpu }}
limits:
memory: {{ .Values.todoapp.resources.limits.memory }}
cpu: {{ .Values.todoapp.resources.limits.cpu }}
env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: app-config
key: PYTHONUNBUFFERED
{{- range $key, $value := .Values.todoapp.secrets }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: app-secret
key: {{ $key }}
{{- end }}
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: api/health
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: api/ready
port: 8080
initialDelaySeconds: 30
periodSeconds: 15
volumes:
- name: data
persistentVolumeClaim:
claimName: pvc-data
- name: app-secrets-volume
secret:
secretName: app-secret
- name: app-config-volume
configMap:
name: app-config
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: {{ .Values.todoapp.nodeAffinity.weight }}
preference:
matchExpressions:
- key: {{ .Values.todoapp.nodeAffinity.key }}
operator: {{ .Values.todoapp.nodeAffinity.operator }}
values:
- {{ .Values.todoapp.nodeAffinity.values }}
25 changes: 25 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: todoapp
namespace: {{ .Values.todoapp.namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: todoapp
minReplicas: {{ .Values.todoapp.HorScaling.minReplicas }}
maxReplicas: {{ .Values.todoapp.HorScaling.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.HorScaling.resourcetarget.cpu }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.HorScaling.resourcetarget.memory }}
18 changes: 18 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/ingress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: todoapp-ingress
namespace: {{ .Values.todoapp.namespace }}
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: todoapp-service
port:
number: 80
Loading