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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/
9 changes: 9 additions & 0 deletions .infrastructure/helm-chart/todoapp/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v2
name: todoapp
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
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: {{ .Chart.Name }}
namespace: {{ .Values.mysql.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.mysql.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.mysql.namespace }}
type: Opaque
data:
{{- range $k, $v := .Values.mysql.secrets }}
{{ $k }}: {{ $v | b64enc}}
{{- 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 }}
namespace: {{ .Values.mysql.namespace }}
spec:
selector:
app: {{ .Chart.Name }}
ports:
- name: {{ .Chart.Name }}
port: {{ .Values.mysql.port }}
clusterIP: {{ .Values.mysql.service.clusterIP }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Chart.Name }}
namespace: {{ .Values.mysql.namespace }}
spec:
selector:
matchLabels:
app: {{ .Chart.Name }}
replicas: {{ .Values.mysql.replicas }}
serviceName: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: {{ .Values.mysql.image.repository}}:{{ .Values.mysql.image.tag}}
env:
{{- range $k, $v := .Values.mysql.secrets }}
- name: {{ $k }}
valueFrom:
secretKeyRef:
name: mysql-secrets
key: {{ $k }}
{{- end }}
- name: MYSQL_DATABASE
value: app_db
ports:
- name: {{ .Chart.Name }}
containerPort: {{ .Values.mysql.port }}
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 }}
limits:
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: {{ .Chart.Name }}
tolerations:
- key: {{ .Values.mysql.tolerations.key}}
operator: {{ .Values.mysql.tolerations.operator}}
value: {{ .Values.mysql.tolerations.value}}
effect: {{ .Values.mysql.tolerations.effect}}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: {{ .Values.mysql.affinity.key }}
operator: {{ .Values.mysql.affinity.operator }}
values:
- {{ .Values.mysql.affinity.values }}
topologyKey: {{ .Values.mysql.affinity.topologyKey }}
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.mysql.affinity.nodeAffinity.key }}
operator: {{ .Values.mysql.affinity.nodeAffinity.operator }}
values:
- {{ .Values.mysql.affinity.nodeAffinity.values }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: {{ .Values.mysql.storage.size }}
42 changes: 42 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mysql:
namespace: mysql

image:
repository: mysql
tag: 8.0
replicas: 2
port: 3306

service:
clusterIP: None

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

resources:
requests:
cpu: "500m"
memory: "1Gi"
limits:
cpu: "1"
memory: "2Gi"
storage:
size: "2Gi"

tolerations:
key: "app"
operator: "Equal"
value: "mysql"
effect: "NoSchedule"

affinity:
key: "app"
operator: In
values: "mysql"
topologyKey: "kubernetes.io/hostname"
nodeAffinity:
key: "app"
operator: In
values: "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: {{ .Chart.Name }}-service
namespace: {{ .Values.todoapp.namespace }}
spec:
type: {{ .Values.todoapp.service.type}}
selector:
app: {{ .Chart.Name }}
ports:
- protocol: TCP
port: {{ .Values.todoapp.service.port}}
targetPort: {{ .Values.todoapp.service.targetPort }}
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.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: {{ .Release.Name }}-{{ .Chart.Name }}
namespace: {{ .Values.todoapp.namespace }}
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 }}-reader
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.todoapp.image.repository}}: {{ .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: {{ .Chart.Name }}-config
key: PYTHONUNBUFFERED
{{- range $k, $v := .Values.todoapp.secrets }}
- name: {{ $k }}
valueFrom:
secretKeyRef:
name: todoapp-secret
key: {{ $k }}
{{- 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: {{ .Chart.Name }}-pvc-data
- name: app-secrets-volume
secret:
secretName: {{ .Chart.Name }}-secret
- name: app-config-volume
configMap:
name: {{ .Chart.Name }}-config
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: app
operator: In
values:
- kube2py
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 }}
namespace: {{ .Values.todoapp.namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Release.Name}} - {{ .Chart.Name }}
minReplicas: {{ .Values.todoapp.autoscaling.minReplicas }}
maxReplicas: {{ .Values.todoapp.autoscaling.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.autoscaling.targetMemoryUtilizationPercentage }}
Loading