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 3 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"
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,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Chart.Name }}-configmap
namespace: {{ .Values.global.namespace }}
labels:
app: {{ .Chart.Name }}
data:
init.sql: {{ .Values.mysql.config.init }}
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.secret }}
{{ $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,58 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Chart.Name }}-statefulset
namespace: {{ .Values.global.namespace }}
spec:
selector:
matchLabels:
app: {{ .Chart.Name }}
replicas: {{ .Values.mysql.statefulSet }}
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.secret }}
- name: {{ $k }}
valueFrom:
secretKeyRef:
name: {{ .Chart.Name }}-secrets
key: {{ $k }}
{{- end }}
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:
{{ .Values.mysql.statefulSet.resources.requests }}
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 }}

Choose a reason for hiding this comment

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

This is not changed.

Copy link
Author

@cth-usq cth-usq May 1, 2024

Choose a reason for hiding this comment

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

You mean I need to unite resources, levenessProbe and readinesP - and import by one link?

because I made changes from previous commit

image

Copy link
Author

Choose a reason for hiding this comment

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

Actually, resources, livenessProbe and readinesS on the same level in code line maybe will be better to keep them as 3 lines

volumes:
- name: config-map
configMap:
name: mysql
tolerations:
{{ .Values.mysql.statefulSet.tolerations }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: {{ .Values.mysql.statefulSet.storage }}
71 changes: 71 additions & 0 deletions .infrastructure/helm-chart/todoapp/charts/mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
mysql:
config:
init: |
GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'%';
USE app_db;
CREATE TABLE counter (
id INT AUTO_INCREMENT PRIMARY KEY,
value INT
);

service:
ports:
name: mysql
port: 3306
clusterIP: None

secret:
MYSQL_ROOT_PASSWORD: 1234
MYSQL_USER: app_user
MYSQL_PASSWORD: 1234

Choose a reason for hiding this comment

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

Same with secrets here.


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

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

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.requests.memory }}

Choose a reason for hiding this comment

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

Тут неправильно імпортований блок, потрібно не лише memory, а весь блок resource конфігурацій.

Choose a reason for hiding this comment

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

Приклад:

    spec:
      containers:
        - name: my-container
          image: my-image:latest
          resources:
            {{ toYaml .Values.resources | nindent 12 }}

Copy link
Author

Choose a reason for hiding this comment

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

@YuriiSmolii my inattention

env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: {{ .Chart.Name }}-config
key: PYTHONUNBUFFERED
{{- range $k := .Values.todoapp.secret }}
- name: {{ $k | upper }}
valueFrom:
secretKeyRef:
name: {{ .Chart.Name }}-secret
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
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.global.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.global.namespace }}
Loading