diff --git a/src/kubernetes/applications.yaml b/src/kubernetes/applications.yaml index 9f5f187..cfa970a 100644 --- a/src/kubernetes/applications.yaml +++ b/src/kubernetes/applications.yaml @@ -10,7 +10,7 @@ spec: project: default source: repoURL: https://github.com/f-lab-clone/ticketing-infra.git - targetRevision: main + targetRevision: HEAD path: src/kubernetes/ticketing-chart destination: diff --git a/src/kubernetes/ticketing-chart/templates/_helpers.tpl b/src/kubernetes/ticketing-chart/templates/_helpers.tpl index fb98e1c..501e098 100644 --- a/src/kubernetes/ticketing-chart/templates/_helpers.tpl +++ b/src/kubernetes/ticketing-chart/templates/_helpers.tpl @@ -42,6 +42,16 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} +{{- define "ticketing-chart.queuingLabels" -}} +helm.sh/chart: {{ include "ticketing-chart.chart" . }} +{{ include "ticketing-chart.queuingSelectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + + {{/* Selector labels */}} @@ -49,3 +59,8 @@ Selector labels app.kubernetes.io/name: {{ include "ticketing-chart.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} + +{{- define "ticketing-chart.queuingSelectorLabels" -}} +app.kubernetes.io/name: {{ include "ticketing-chart.name" . }}-queuing +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/src/kubernetes/ticketing-chart/templates/deployment-queuing.yaml b/src/kubernetes/ticketing-chart/templates/deployment-queuing.yaml new file mode 100644 index 0000000..0b3c5fa --- /dev/null +++ b/src/kubernetes/ticketing-chart/templates/deployment-queuing.yaml @@ -0,0 +1,99 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ticketing-queuing-api + labels: + {{- include "ticketing-chart.queuingLabels" . | nindent 4 }} + namespace: {{ .Values.namespace }} +spec: + selector: + matchLabels: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 8 }} + spec: + nodeSelector: + role: backend + + containers: + - name: ticketing-queuing-api + image: "{{ .Values.queuing_system.image.repository }}:{{ .Values.queuing_system.image.tag }}" + + resources: + requests: + cpu: "100m" + memory: "100Mi" + + imagePullPolicy: Always + command: ['npm', 'run', 'start:api'] + + ports: + - name: http + containerPort: {{ .Values.queuing_system.config.PORT }} + protocol: TCP + + env: + - name: NODE_ENV + value: "{{ .Values.queuing_system.config.NODE_ENV }}" + - name: PORT + value: "{{ .Values.queuing_system.config.PORT }}" + - name: REDIS_HOST + value: "{{ .Values.queuing_system.config.REDIS_HOST }}" + - name: REDIS_PORT + value: "{{ .Values.queuing_system.config.REDIS_PORT }}" + + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ticketing-queuing-job + labels: + {{- include "ticketing-chart.queuingLabels" . | nindent 4 }} + namespace: {{ .Values.namespace }} +spec: + selector: + matchLabels: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 8 }} + spec: + nodeSelector: + role: backend + + containers: + - name: ticketing-queuing-api + image: "{{ .Values.queuing_system.image.repository }}:{{ .Values.queuing_system.image.tag }}" + + resources: + requests: + cpu: "100m" + memory: "100Mi" + + imagePullPolicy: Always + command: ['npm', 'run', 'start:job'] + + env: + - name: NODE_ENV + value: "{{ .Values.queuing_system.config.NODE_ENV }}" + - name: REDIS_HOST + value: "{{ .Values.queuing_system.config.REDIS_HOST }}" + - name: REDIS_PORT + value: "{{ .Values.queuing_system.config.REDIS_PORT }}" + - name: JOB_INTEVAL_SEC + value: "{{ .Values.queuing_system.config.JOB_INTEVAL_SEC }}" + - name: JOB_MOVE_PER_INTEVAL + value: "{{ .Values.queuing_system.config.JOB_MOVE_PER_INTEVAL }}" + - name: JOB_TICKET_EXPIRED_SEC + value: "{{ .Values.queuing_system.config.JOB_TICKET_EXPIRED_SEC }}" \ No newline at end of file diff --git a/src/kubernetes/ticketing-chart/templates/redis.yaml b/src/kubernetes/ticketing-chart/templates/redis.yaml new file mode 100644 index 0000000..76dc958 --- /dev/null +++ b/src/kubernetes/ticketing-chart/templates/redis.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ticketing-redis + labels: + {{- include "ticketing-chart.queuingLabels" . | nindent 4 }} + namespace: {{ .Values.namespace }} +spec: + selector: + matchLabels: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 8 }} + spec: + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + + containers: + - name: redis + image: {{ .Values.redis.image }} + command: + - redis-server + env: + - name: MASTER + value: "true" + ports: + - name: redis + containerPort: {{ .Values.redis.port }} +--- +apiVersion: v1 +kind: Service +metadata: + name: ticketing-redis + namespace: {{ .Values.namespace }} +spec: + type: ClusterIP + ports: + - port: {{ .Values.redis.port }} + targetPort: {{ .Values.redis.port }} + selector: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 4 }} \ No newline at end of file diff --git a/src/kubernetes/ticketing-chart/templates/service.yaml b/src/kubernetes/ticketing-chart/templates/service.yaml index 95ac85f..5c71713 100644 --- a/src/kubernetes/ticketing-chart/templates/service.yaml +++ b/src/kubernetes/ticketing-chart/templates/service.yaml @@ -13,6 +13,19 @@ spec: --- apiVersion: v1 kind: Service +metadata: + name: {{ include "ticketing-chart.fullname" . }}-queuing-api + namespace: {{ .Values.namespace }} +spec: + type: ClusterIP + ports: + - port: {{ .Values.queuing_system.config.PORT }} + targetPort: {{ .Values.queuing_system.config.PORT }} + selector: + {{- include "ticketing-chart.queuingSelectorLabels" . | nindent 4 }} +--- +apiVersion: v1 +kind: Service metadata: name: prometheus-grafana-node-port namespace: monitoring diff --git a/src/kubernetes/ticketing-chart/values.yaml b/src/kubernetes/ticketing-chart/values.yaml index 6e01b13..64c55fa 100644 --- a/src/kubernetes/ticketing-chart/values.yaml +++ b/src/kubernetes/ticketing-chart/values.yaml @@ -13,4 +13,25 @@ backend: autoscaling: enabled: true - replicaCount: 1 \ No newline at end of file + replicaCount: 1 + + +redis: + image: redis:latest + port: 6379 + + +queuing_system: + image: + repository: 213060417361.dkr.ecr.ap-northeast-2.amazonaws.com/ticketing-queuing-ecr + pullPolicy: Always + tag: "latest" + + config: + NODE_ENV: development + PORT: 8000 + REDIS_HOST: ticketing-redis.default.svc.cluster.local + REDIS_PORT: 6379 + JOB_INTEVAL_SEC: 10 + JOB_MOVE_PER_INTEVAL: 100 + JOB_TICKET_EXPIRED_SEC: 180 \ No newline at end of file diff --git a/src/terraform/ecr.tf b/src/terraform/ecr.tf index c986edc..288585f 100644 --- a/src/terraform/ecr.tf +++ b/src/terraform/ecr.tf @@ -10,12 +10,43 @@ module "ecr" { rules = [ { rulePriority = 1, - description = "Keep last 30 images", + description = "Keep last 10 images", selection = { tagStatus = "tagged", tagPrefixList = ["v"], countType = "imageCountMoreThan", - countNumber = 30 + countNumber = 10 + }, + action = { + type = "expire" + } + } + ] + }) + + tags = { + Environment = "development" + } +} + +module "ecr-queuing" { + source = "terraform-aws-modules/ecr/aws" + + repository_name = "ticketing-queuing-ecr" + + repository_image_tag_mutability = "MUTABLE" + repository_force_delete = true + + repository_lifecycle_policy = jsonencode({ + rules = [ + { + rulePriority = 1, + description = "Keep last 10 images", + selection = { + tagStatus = "tagged", + tagPrefixList = ["v"], + countType = "imageCountMoreThan", + countNumber = 10 }, action = { type = "expire"