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 #7

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
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
5 changes: 5 additions & 0 deletions .infrastructure/helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: todoapp
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
5 changes: 5 additions & 0 deletions .infrastructure/helm-chart/Chart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: todoapp
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
5 changes: 5 additions & 0 deletions .infrastructure/helm-chart/charts/mysql/Chart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: mysql
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
15 changes: 15 additions & 0 deletions .infrastructure/helm-chart/charts/mysql/templates/configMap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Chart.Name }}-configMap
namespace: {{ .Values.namespace.mysql.name }}
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
);
4 changes: 4 additions & 0 deletions .infrastructure/helm-chart/charts/mysql/templates/ns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.namespace.mysql.name }}
10 changes: 10 additions & 0 deletions .infrastructure/helm-chart/charts/mysql/templates/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Chart.Name }}-secrets
namespace: {{ .Values.global.namespace }}
type: Opaque
data:
{{- range $key, $val := .Values.mysql.secret }}
{{ $key | upper }}: {{ $val | b64enc | quote}}
{{- end }}
12 changes: 12 additions & 0 deletions .infrastructure/helm-chart/charts/mysql/templates/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name}}-service
namespace: {{ .Values.namespace.mysql.name }}
spec:
selector:
app: mysql
ports:
- name: mysql
port: 3306
clusterIP: None
89 changes: 89 additions & 0 deletions .infrastructure/helm-chart/charts/mysql/templates/statefulSet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Chart.Name }}-statefulSet
namespace: {{ .Values.namespace.mysql.name }}
spec:
selector:
matchLabels:
app: mysql
replicas: {{ .Values.hpa.mysql.minReplicas }}
serviceName: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: {{ .Values.image.mysql.repository }}:{{ .Values.image.mysql.tag }}
env:
{{- range $v, $k := .Values.mysql.secret }}
- name: {{ $v }}
valueFrom:
secretKeyRef:
name: {{ $v }}
key: {{ $k | b64enc | quote }}
{{- end }}
- name: value
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.limits.cpu }}
memory: {{ .Values.mysql.resources.limits.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: {{ .Values.mysql.affinity.nodeAffinity.values }}
tolerations:
- key: {{ .Values.mysql.affinity.nodeAffinity.key }}
operator: "Equal"
value: "mysql"
effect: "NoSchedule"
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: {{ .Values.mysql.affinity.nodeAffinity.key }}
operator: In
values:
- {{ .Values.mysql.affinity.nodeAffinity.values }}
topologyKey: "kubernetes.io/hostname"
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.mysql.affinity.nodeAffinity.key }}
operator: In
values:
- {{ .Values.mysql.affinity.nodeAffinity.values }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: {{ .Values.mysql.resources.requests.storage }}
46 changes: 46 additions & 0 deletions .infrastructure/helm-chart/charts/mysql/values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace:
mysql:
name: mysql-helm
mysql:
secret:
MYSQL_ROOT_PASSWORD: "MTIzNA=="
MYSQL_USER: "YXBwX3VzZXI="
MYSQL_PASSWORD: "MTIzNA=="
resources:
requests:
cpu: "100m"
memory: "128Mi"
storage: "2Gi"
limits:
cpu: "500m"
memory: "1Gi"

rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%

affinity:
nodeAffinity:
key: "app"
values: mysql


image:
mysql:
repository: mysql
tag: "8.0"

hpa:
mysql:
minReplicas: 2
maxReplicas: 10
cpuUtilization: 50
memoryUtilization: 70

persistentVolume:
capacity: "1Gi"

persistentVolumeClaim:
storage: "1Gi"

serviceAccount: mysql
13 changes: 13 additions & 0 deletions .infrastructure/helm-chart/templates/clusterIp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}-clusterIp
namespace: {{ .Values.namespace.todoapp.name }}
spec:
type: ClusterIP
selector:
app: todoapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
7 changes: 7 additions & 0 deletions .infrastructure/helm-chart/templates/configMap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Chart.Name }}-configMap
namespace: {{ .Values.namespace.todoapp.name }}
data:
PYTHONUNBUFFERED: "1"
81 changes: 81 additions & 0 deletions .infrastructure/helm-chart/templates/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Chart.Name }}-deployment
namespace: {{ .Values.namespace.todoapp.name }}
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: {{ .Values.todoapp.rollingUpdate.maxSurge }}
maxUnavailable: {{ .Values.todoapp.rollingUpdate.maxUnavailable }}
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
serviceAccountName: {{ .Chart.Name }}-secrets-reader
containers:
- name: todoapp
image: {{ .Values.image.todoapp.repository}}: {{.Values.image.todoapp.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:
{{ toYaml .Values.todoapp.resources | nindent 12 }}
env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: {{ .Chart.Name }}-config
key: PYTHONUNBUFFERED
{{- range $v, $k := .Values.todoapp.secret }}
- name: {{ $k }}
valueFrom:
secretKeyRef:
name: {{ $v }}
key: {{ $k | b64enc | quote}}
{{- end }}
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: api/health
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
readinessProbe:
httpGet:
path: api/ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
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: 1
preference:
matchExpressions:
- key: {{ .Values.todoapp.affinity.nodeAffinity.key }}
operator: In
values:
- {{ .Values.todoapp.affinity.nodeAffinity.values }}
25 changes: 25 additions & 0 deletions .infrastructure/helm-chart/templates/hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Chart.Name }}-hpa
namespace: {{ .Values.namespace.todoapp.name }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: todoapp
minReplicas: {{ .Values.hpa.todoapp.minReplicas }}
maxReplicas: {{ .Values.hpa.todoapp.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.hpa.todoapp.cpuUtilization }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.hpa.todoapp.memoryUtilization }}
18 changes: 18 additions & 0 deletions .infrastructure/helm-chart/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: {{ .Chart.Name }}-ingress
namespace: {{ .Values.todoapp.namespace }}
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- pathType: Prefix
path: /(|$)(.*)
backend:
service:
name: {{ .Chart.Name }}-service
port:
number: 80
14 changes: 14 additions & 0 deletions .infrastructure/helm-chart/templates/nodeport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}-nodeport
namespace: {{ .Values.namespace.todoapp.name }}
spec:
type: NodePort
selector:
app: todoapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 30007
4 changes: 4 additions & 0 deletions .infrastructure/helm-chart/templates/ns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.namespace.todoapp.name }}
14 changes: 14 additions & 0 deletions .infrastructure/helm-chart/templates/pv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ .Chart.Name }}-pv
namespace: {{ .Values.namespace.todoapp.name }}
spec:
storageClassName: standard
persistentVolumeReclaimPolicy: Delete
accessModes:
- ReadWriteMany
capacity:
storage: {{ .Values.persistentVolume.todoapp.capacity }}
hostPath:
path: /data/
12 changes: 12 additions & 0 deletions .infrastructure/helm-chart/templates/pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Chart.Name }}-pvc
namespace: {{ .Values.namespace.todoapp.name }}
spec:
volumeName: pv-data
accessModes:
- ReadWriteMany
resources:
requests:
storage: {{ .Values.persistentVolumeClaim.todoapp.storage }}
Loading