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:1.0 #2

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
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/
14 changes: 14 additions & 0 deletions .infrastructure/helm-chart/todoapp/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v2
name: todoapp
description: A Helm chart for Kubernetes

type: application

version: 0.1.0

appVersion: "1.16.0"

dependencies:
- name: mysql
version: 0.1.0
repository: "file://charts/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/
9 changes: 9 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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: {{ .Chart.Name }}-configmap
namespace: {{ .Values.global.namespace }}
labels:
app: {{ .Chart.Name }}
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.global.namespace }}
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 $k, $v := .Values.mysql.secrets }}
{{ $k | upper }}: {{ $v | b64enc | quote }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Headless service for stable DNS entries of StatefulSet members.
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}-clusterip
namespace: {{ .Values.global.namespace }}
spec:
selector:
app: {{ .Chart.Name }}
ports:
- name: {{ .Values.mysql.service.ports.name }}
port: {{ .Values.mysql.service.ports.port }}
clusterIP: {{ .Values.mysql.service.clusterIP }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Chart.Name }}-statefulset
namespace: {{ .Values.global.namespace }}
spec:
selector:
matchLabels:
app: {{ .Chart.Name }}
replicas: {{ .Values.mysql.statefulSet.replicas }}
serviceName: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Values.mysql.statefulSet.name }}
image: {{ .Values.mysql.statefulSet.repository }}:{{ .Values.mysql.statefulSet.version }}
env:
{{- range $k := .Values.mysql.secrets }}
- name: {{ $k | upper }}
valueFrom:
secretKeyRef:
name: mysql-secrets
key: {{ $k | upper }}
{{- end }}
resources:
requests:
{{ .Values.mysql.statefulSet.resources.requests }}
ports:
- name: mysql
containerPort: 3306
volumeMounts:
- name: data
mountPath: /var/lib/mysql
subPath: mysql
- name: config-map
mountPath: /docker-entrypoint-initdb.d
livenessProbe:

Choose a reason for hiding this comment

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

You could import the whole block from values. And same for other below

{{ .Values.mysql.statefulSet.livenessProbe }}
readinessProbe:
{{ .Values.mysql.statefulSet.readinessProbe }}
volumes:
- name: config-map
configMap:
name: mysql
tolerations:
{{- range .Values.mysql.statefulSet.tolerations }}
- key: "{{ .key }}"
operator: "{{ .operator }}"
value: "{{ .value }}"
effect: "{{ .effect }}"
{{- end }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: {{ .Values.mysql.statefulSet.storage }}
62 changes: 62 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
mysql:
service:
ports:
name: mysql
port: 3306
clusterIP: None

secrets:
MYSQL_ROOT_PASSWORD: "1234"
MYSQL_USER: "app_user"
MYSQL_PASSWORD: "1234"

statefulSet:
replicas: 2
name: mysql
repository: mysql
version: 8.0
storage: 2Gi

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

livenessProbe:
exec:
command: ["mysqladmin", "ping"]
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5

readinessProbe:
exec:
command: ["mysqladmin", "ping"]
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1

affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- mysql
topologyKey: "kubernetes.io/hostname"
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "app"
operator: In
values:
- "mysql"

tolerations:
- key: "app"
operator: "Equal"
value: "mysql"
effect: "NoSchedule"
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: {{ .Chart.Name }}-service
namespace: {{ .Values.global.namespace }}
spec:
type: ClusterIP
selector:
app: {{ .Chart.Name }}
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: {{ .Chart.Name }}-config
namespace: {{ .Values.global.namespace }}
data:
PYTHONUNBUFFERED: {{ .Values.todoapp.configs.PYTHONUNBUFFERED }}
73 changes: 73 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}
namespace: {{ .Values.global.namespace }}
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: {{ .Values.todoapp.rollingUpdate.maxSurge }}
maxUnavailable: {{ .Values.todoapp.rollingUpdate.maxSurge }}
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
serviceAccountName: {{ .Chart.Name }}-secrets-reader
containers:
- name: {{ .Values.todoapp.image.name }}
image: {{ .Values.todoapp.image.repository }}:{{ .Values.todoapp.image.version }}
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:
{{ .Values.todoapp.resources }}
env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: {{ .Chart.Name }}-config
key: PYTHONUNBUFFERED
{{- range $k := .Values.todoapp.secrets }}
- name: {{ $k | upper }}
valueFrom:
secretKeyRef:
name: todoapp-secrets
key: {{ $k | upper }}
{{- 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:
{{ .Values.todoapp.affinity }}
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: {{ .Chart.Name }}-hpa
namespace: {{ .Values.global.namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Release.Name }}-{{ .Chart.Name }}
minReplicas: {{ .Values.todoapp.hpa.minReplicas }}
maxReplicas: {{ .Values.todoapp.hpa.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.hpa.cpu.averageUtilization }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.hpa.memory.averageUtilization }}
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: {{ .Chart.Name }}-ingress
namespace: {{ .Values.global.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
Loading