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

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
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.0
appVersion: "1.16.0"
dependencies:
- name: mysql
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
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/
24 changes: 24 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: mysql
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
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 }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the mysql.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the ConfigMap in the specified namespace.

Choose a reason for hiding this comment

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

The mysql.namespace value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to the values.yaml file to avoid deployment issues.

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: {{ .Chart.Name }}
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 }}

Choose a reason for hiding this comment

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

Ensure that the mysql.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the Secret in the specified namespace.

Choose a reason for hiding this comment

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

The mysql.namespace value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to the values.yaml file to avoid deployment issues.

type: Opaque
data:
{{- range $k, $v := .Values.mysql.secret }}
{{ $k }}: {{ $v }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
{{ end }}
Comment on lines +8 to +10

Choose a reason for hiding this comment

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

Ensure that the mysql.secret values are defined in the values.yaml file. This is necessary for populating the Secret data correctly.

Comment on lines +8 to +10

Choose a reason for hiding this comment

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

The mysql.secret value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to the values.yaml file to properly configure secrets.

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: {{ .Chart.Name }}
namespace: {{ .Values.mysql.namespace }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the mysql.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the Service in the specified namespace.

Choose a reason for hiding this comment

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

The mysql.namespace value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to the values.yaml file to avoid deployment issues.

spec:
selector:
app: {{ .Chart.Name }}
ports:
- name: {{ .Chart.Name }}
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,89 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Chart.Name }}
namespace: {{ .Values.mysql.namespace}}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the mysql.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the StatefulSet in the specified namespace.

Choose a reason for hiding this comment

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

The mysql.namespace value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to avoid deployment issues.

spec:
selector:
matchLabels:
app: {{ .Chart.Name }}
replicas: {{ .Values.mysql.replicas }}

Choose a reason for hiding this comment

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

Ensure that the mysql.replicas value is defined in the values.yaml file. This is necessary to control the number of replicas for the StatefulSet.

Choose a reason for hiding this comment

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

The mysql.replicas value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to control the number of replicas.

serviceName: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: {{ .Values.mysql.image.repository }}:{{ .Values.mysql.image.tag }}

Choose a reason for hiding this comment

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

Ensure that the mysql.image.repository and mysql.image.tag values are defined in the values.yaml file. These are necessary for specifying the correct image for the container.

Choose a reason for hiding this comment

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

The mysql.image.repository and mysql.image.tag values are referenced here, but they are not defined in the values.yaml file. Ensure that these values are added to specify the image details.

env:
{{- range $k, $v := .Values.mysql.secret }}
- name: {{ $k }}
valueFrom:
secretKeyRef:
name: mysql-secrets
key: {{ $k }}
{{- end }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
- name: MYSQL_DATABASE
value: app_db
ports:
- name: {{ .Chart.Name }}
containerPort: 3306
volumeMounts:
- name: data
mountPath: /var/lib/mysql
subPath: {{ .Chart.Name }}
- name: config-map
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
cpu: {{ .Values.mysql.resources.requests.cpu }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

The mysql.resources.requests.cpu and mysql.resources.requests.memory values are referenced here, but they are not defined in the values.yaml file. Ensure that these values are added to specify resource requests.

memory: {{ .Values.mysql.resources.requests.memory }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +41 to +42

Choose a reason for hiding this comment

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

Ensure that the mysql.resources.requests.cpu and mysql.resources.requests.memory values are defined in the values.yaml file. These are necessary for specifying resource requests for the container.

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 }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the mysql.tolerations.key value is defined in the values.yaml file. This is necessary for specifying tolerations for the StatefulSet.

operator: {{ .Values.mysql.tolerations.operator }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
value: {{ .Values.mysql.tolerations.value }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
effect: {{ .Values.mysql.tolerations.effect }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

The mysql.tolerations values are referenced here, but they are not defined in the values.yaml file. Ensure that these values are added to specify toleration parameters.

affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: {{ .Values.mysql.affinities.podAntiAffinity.key}}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the mysql.affinities.podAntiAffinity.key value is defined in the values.yaml file. This is necessary for specifying pod anti-affinity rules for the StatefulSet.

operator: {{ .Values.mysql.affinities.podAntiAffinity.operator}}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
values:
- {{ .Values.mysql.affinities.podAntiAffinity.values}}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
topologyKey: "kubernetes.io/hostname"
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.mysql.affinities.nodeAffinity.key }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the mysql.affinities.nodeAffinity.key value is defined in the values.yaml file. This is necessary for specifying node affinity rules for the StatefulSet.

operator: {{ .Values.mysql.affinities.nodeAffinity.operator }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
values:
- {{ .Values.mysql.affinities.nodeAffinity.values }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

The mysql.affinities values are referenced here, but they are not defined in the values.yaml file. Ensure that these values are added to specify affinity parameters.

volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: {{ .Values.mysql.pvcStorageRequest }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the mysql.pvcStorageRequest value is defined in the values.yaml file. This is necessary for specifying the storage request for the PersistentVolumeClaim.

Choose a reason for hiding this comment

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

The mysql.pvcStorageRequest value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to specify the storage request for PVC.

36 changes: 36 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mysql:
namespace: mysql

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

replicas: 2

image:
repository: mysql
tag: 8.0

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

pvcStorageRequest: 2Gi

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

affinities:
podAntiAffinity:
key: "app"
operator: In
values: "mysql"
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 }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the todoapp.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the Service in the specified namespace.

Choose a reason for hiding this comment

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

The todoapp.namespace value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to avoid deployment issues.

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: {{ .Chart.Name }}-config
namespace: {{ .Values.todoapp.namespace }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the todoapp.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the ConfigMap in the specified namespace.

Choose a reason for hiding this comment

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

The todoapp.namespace value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to avoid deployment issues.

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: {{ .Chart.Name }}
namespace: {{ .Values.todoapp.namespace }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the todoapp.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the Deployment in the specified namespace.

spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: {{ .Values.todoapp.rollingUpdate.maxSurge }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
maxUnavailable: {{ .Values.todoapp.rollingUpdate.maxUnavailable }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +10 to +11

Choose a reason for hiding this comment

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

Ensure that the todoapp.rollingUpdate.maxSurge and todoapp.rollingUpdate.maxUnavailable values are defined in the values.yaml file. These are necessary for controlling the rolling update strategy.

selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
serviceAccountName: {{ .Values.todoapp.RBAC.name }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the todoapp.RBAC.name value is defined in the values.yaml file. This is necessary for specifying the service account name.

containers:
- name: {{ .Chart.Name }}
image: {{ .Values.todoapp.image.repository}}:{{ .Values.todoapp.image.tag }}

Choose a reason for hiding this comment

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

Ensure that the todoapp.image.repository and todoapp.image.tag values are defined in the values.yaml file. These are necessary for specifying the correct image for the container.

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 }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
cpu: {{ .Values.todoapp.resources.requests.cpu }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
limits:
memory: {{ .Values.todoapp.resources.limits.memory }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
cpu: {{ .Values.todoapp.resources.limits.cpu }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +35 to +39

Choose a reason for hiding this comment

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

Ensure that the todoapp.resources.requests.memory, todoapp.resources.requests.cpu, todoapp.resources.limits.memory, and todoapp.resources.limits.cpu values are defined in the values.yaml file. These are necessary for specifying resource requests and limits for the container.

env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: {{ .Chart.Name }}-config
key: PYTHONUNBUFFERED
{{- range $k, $v := .Values.todoapp.secrets }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
- name: {{ $k }}
valueFrom:
secretKeyRef:
name: todoapp-secret
key: {{ $k }}
{{- end }}
Comment on lines +46 to +52

Choose a reason for hiding this comment

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

Ensure that the todoapp.secrets values are defined in the values.yaml file. This is necessary for populating the environment variables from secrets.

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
- 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 }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: todoapp
minReplicas: {{ .Values.todoapp.hpa.minReplicas }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
maxReplicas: {{ .Values.todoapp.hpa.maxReplicas }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.hpa.resourceAvgUtilization.cpu }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.todoapp.hpa.resourceAvgUtilization.memory }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved
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 }}
LevAndrii marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Ensure that the todoapp.namespace value is defined in the values.yaml file. This is crucial for the correct deployment of the Ingress in the specified namespace.

Choose a reason for hiding this comment

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

The todoapp.namespace value is referenced here, but it is not defined in the values.yaml file. Ensure that this value is added to avoid deployment issues.

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
Loading