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

Open
wants to merge 7 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ cover/
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
Expand Down
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
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 $key, $value := .Values.mysql.secrets }}
{{ $key | upper }}: {{ $value }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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,77 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Chart.Name }}
namespace: {{ .Values.mysql.namespace }}
spec:
replicas: {{ .Values.mysql.replicas }}
serviceName: {{ .Chart.Name }}
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.mysql.image.repository }}:{{ .Values.mysql.image.tag }}"
env:
{{- range $key, $val := .Values.mysql.secrets }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: mysql-secrets
key: {{ $key }}
{{- end }}
- name: MYSQL_DATABASE
value: app_db
ports:
- name: {{ .Chart.Name }}
containerPort: {{ .Values.mysql.port }}
volumeMounts:
- name: data
mountPath: /var/lib/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
readinessProbe:
exec:
command: ["mysqladmin", "ping"]
initialDelaySeconds: 5
periodSeconds: 2
volumes:
- name: config-map
configMap:
name: {{ .Chart.Name }}
tolerations:
{{ toYaml .Values.mysql.tolerations | nindent 8 }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "app"
operator: In
values:
- {{ .Chart.Name }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: {{ .Values.mysql.storage.size }}
49 changes: 49 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
mysql:
namespace: mysql
image:
repository: mysql
tag: 8.0
replicas: 2
port: 3306

service:
clusterIP: None

secrets:
MYSQL_ROOT_PASSWORD: "MTIzNA=="
MYSQL_USER: "YXBwX3VzZXI="
MYSQL_PASSWORD: "MTIzNA=="

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

tolerations:
- key: "app"
operator: "Equal"
value: "mysql"
effect: "NoSchedule"
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"
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"
79 changes: 79 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}
namespace: {{ .Values.todoapp.namespace }}
spec:
replicas: {{ .Values.todoapp.replicaCount | default 1 }}
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: {{ .Values.todoapp.rollingUpdate.maxSurge | default 1 }}
maxUnavailable: {{ .Values.todoapp.rollingUpdate.maxUnavailable | default 1 }}
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
serviceAccountName: {{ .Chart.Name }}-secrets-reader
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.todoapp.image.repository }}:{{ .Values.todoapp.image.tag }}"
ports:
- containerPort: {{ .Values.todoapp.service.targetPort }}
env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: {{ .Chart.Name }}-config
key: PYTHONUNBUFFERED
{{- range $key, $value := .Values.todoapp.secrets }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: todoapp-secret
key: {{ $key }}
{{- end }}
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 }}
livenessProbe:
{{- toYaml .Values.todoapp.livenessProbe | nindent 10 }}
readinessProbe:
{{- toYaml .Values.todoapp.readinessProbe | nindent 10 }}
volumeMounts:
- name: data
mountPath: /app/data
- name: app-secrets-volume
mountPath: /app/secrets
readOnly: true
- name: app-config-volume
mountPath: /app/configs
readOnly: true
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 }}-hpa
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 }}
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.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/todoapp/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.todoapp.namespace }}
spec:
type: NodePort
selector:
app: {{ .Chart.Name }}
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 30007
4 changes: 4 additions & 0 deletions .infrastructure/helm-chart/todoapp/templates/ns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.todoapp.namespace }}
Loading