Skip to content

Commit

Permalink
Feat/80 deploy queue (#83)
Browse files Browse the repository at this point in the history
* feat: add ecr

* feat: add redis

* feat: add queue system values

* feat: add redis service

* feat: add queuing api

* feat: add labels

* feat: add queuing api service

* feat: add job

* fix: rollback for merge
  • Loading branch information
junha-ahn authored Oct 20, 2023
1 parent 8cb903e commit bc08723
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/kubernetes/applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions src/kubernetes/ticketing-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,25 @@ 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
*/}}
{{- define "ticketing-chart.selectorLabels" -}}
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 }}
99 changes: 99 additions & 0 deletions src/kubernetes/ticketing-chart/templates/deployment-queuing.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"
45 changes: 45 additions & 0 deletions src/kubernetes/ticketing-chart/templates/redis.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 13 additions & 0 deletions src/kubernetes/ticketing-chart/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion src/kubernetes/ticketing-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,25 @@ backend:

autoscaling:
enabled: true
replicaCount: 1
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
35 changes: 33 additions & 2 deletions src/terraform/ecr.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit bc08723

Please sign in to comment.