From 65a068cecee91022ee49f88a30ab123fbcbd4f88 Mon Sep 17 00:00:00 2001 From: yhchae Date: Sun, 3 Aug 2025 17:59:25 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=20API=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/main.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 2025/helm/dst03106/main.go diff --git a/2025/helm/dst03106/main.go b/2025/helm/dst03106/main.go new file mode 100644 index 0000000..85efa87 --- /dev/null +++ b/2025/helm/dst03106/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" +) + +func healthcheckHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + fmt.Fprint(w, `{"status": "ok"}`) +} + +func myHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + fmt.Fprintln(w, `{"message": "Hello world"}`) +} + +func getPort() string { + if port := os.Getenv("PORT"); port != "" { + return port + } + return "8080" +} + +func main() { + http.HandleFunc("/healthcheck", healthcheckHandler) + http.HandleFunc("/api/v1/dst03106", myHandler) + + port := getPort() + host := "0.0.0.0" + log.Printf("Server running on http://%s:%s\n", host, port) + err := http.ListenAndServe(host+":"+port, nil) + if err != nil { + log.Fatalf("Failed to start server: %v", err) + } +} From 152534361fb5fafcb3b38758c93b93f760591f10 Mon Sep 17 00:00:00 2001 From: yhchae Date: Sun, 3 Aug 2025 18:00:12 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=EC=A0=81?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=208080=20=ED=8F=AC=ED=8A=B8=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=8F=99=EC=9E=91=ED=95=98=EB=8F=84=EB=A1=9D=20Doc?= =?UTF-8?q?kerfile=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 2025/helm/dst03106/Dockerfile diff --git a/2025/helm/dst03106/Dockerfile b/2025/helm/dst03106/Dockerfile new file mode 100644 index 0000000..3452245 --- /dev/null +++ b/2025/helm/dst03106/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:alpine AS builder +WORKDIR /app +COPY main.go . +RUN go build -o main main.go + +FROM scratch +COPY --from=builder /app/main /main + +ENV PORT=8080 +EXPOSE 8080 +ENTRYPOINT ["/main"] From 7ebecefdf5c66e08f318502e7fa71ff10bfde1c9 Mon Sep 17 00:00:00 2001 From: yhchae Date: Sun, 3 Aug 2025 18:01:42 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20Helm=20Chart=EC=97=90=20NodePort=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=ED=8F=AC=ED=8A=B8=20?= =?UTF-8?q?=EB=85=B8=EC=B6=9C=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/charts/Chart.yaml | 5 ++++ .../dst03106/charts/templates/_helpers.tpl | 7 ++++++ .../dst03106/charts/templates/deployment.yaml | 23 +++++++++++++++++++ .../dst03106/charts/templates/service.yaml | 16 +++++++++++++ 2025/helm/dst03106/charts/values.yaml | 12 ++++++++++ 5 files changed, 63 insertions(+) create mode 100644 2025/helm/dst03106/charts/Chart.yaml create mode 100644 2025/helm/dst03106/charts/templates/_helpers.tpl create mode 100644 2025/helm/dst03106/charts/templates/deployment.yaml create mode 100644 2025/helm/dst03106/charts/templates/service.yaml create mode 100644 2025/helm/dst03106/charts/values.yaml diff --git a/2025/helm/dst03106/charts/Chart.yaml b/2025/helm/dst03106/charts/Chart.yaml new file mode 100644 index 0000000..bc8e848 --- /dev/null +++ b/2025/helm/dst03106/charts/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v2 +name: my-service +description: A minimal Helm chart for my app +version: 0.1.0 +appVersion: "1.0" diff --git a/2025/helm/dst03106/charts/templates/_helpers.tpl b/2025/helm/dst03106/charts/templates/_helpers.tpl new file mode 100644 index 0000000..0029f91 --- /dev/null +++ b/2025/helm/dst03106/charts/templates/_helpers.tpl @@ -0,0 +1,7 @@ +{{- define "my-chart.name" -}} +{{- .Chart.Name -}} +{{- end -}} + +{{- define "my-chart.fullname" -}} +{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/2025/helm/dst03106/charts/templates/deployment.yaml b/2025/helm/dst03106/charts/templates/deployment.yaml new file mode 100644 index 0000000..3059e65 --- /dev/null +++ b/2025/helm/dst03106/charts/templates/deployment.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "my-chart.fullname" . }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ include "my-chart.name" . }} + template: + metadata: + labels: + app: {{ include "my-chart.name" . }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.name }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.targetPort }} # 문서화용 데이터 + # List of ports to expose from the container. + # Not specifying a port here DOES NOT prevent that port from being exposed. + # Any port which is listening on the default "0.0.0.0" address inside a container will be accessible from the network. diff --git a/2025/helm/dst03106/charts/templates/service.yaml b/2025/helm/dst03106/charts/templates/service.yaml new file mode 100644 index 0000000..f0a89db --- /dev/null +++ b/2025/helm/dst03106/charts/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "my-chart.fullname" . }} +spec: + type: {{ .Values.service.type }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: {{ .Values.service.targetPort }} + {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) .Values.service.nodePort }} + nodePort: {{ .Values.service.nodePort }} + {{- end }} + protocol: TCP + selector: # 어떤 파드에 트래픽을 보낼지 라벨로 선택 + app: {{ include "my-chart.name" . }} diff --git a/2025/helm/dst03106/charts/values.yaml b/2025/helm/dst03106/charts/values.yaml new file mode 100644 index 0000000..2ec266e --- /dev/null +++ b/2025/helm/dst03106/charts/values.yaml @@ -0,0 +1,12 @@ +replicaCount: 1 + +image: + name: my-app:latest + pullPolicy: IfNotPresent + +service: + type: NodePort + port: 80 # Service가 제공하는 포트 번호 (클러스터 내부에서 사용) + nodePort: 30080 # 클러스터 외부에서 노드 IP를 통해 접근하는 포트 번호 + targetPort: 8080 # 실제 Pod 내부 컨테이너의 포트 번호 + # 30080 포트 요청 -> Kubernetes Service (80) -> 선택된 Pod의 컨테이너 내부 포트(8080)으로 전달 From 2d3ef925fc75b73ea8ba28e6d8184b6acd35342a Mon Sep 17 00:00:00 2001 From: yhchae Date: Sun, 3 Aug 2025 18:02:01 +0900 Subject: [PATCH 4/9] =?UTF-8?q?chore:=20=EC=9E=90=EC=A3=BC=20=EC=93=B0?= =?UTF-8?q?=EB=8A=94=20=EB=AA=85=EB=A0=B9=EC=96=B4=EB=A5=BC=20Makefile?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/Makefile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 2025/helm/dst03106/Makefile diff --git a/2025/helm/dst03106/Makefile b/2025/helm/dst03106/Makefile new file mode 100644 index 0000000..d081112 --- /dev/null +++ b/2025/helm/dst03106/Makefile @@ -0,0 +1,31 @@ +CLUSTER_NAME=my-cluster +APP_NAME=my-app +NAMESPACE=my-namespace +CHART_PATH=./charts + +.PHONY: docker-build create-cluster delete-cluster install helm-debug pod-debug test + +docker-build: + docker build -t $(APP_NAME):latest . + +create-cluster: + k3d cluster create ${CLUSTER_NAME} --port "30080:30080@loadbalancer" + k3d image import ${APP_NAME}:latest -c ${CLUSTER_NAME} + docker exec k3d-${CLUSTER_NAME}-server-0 sh -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' + +delete-cluster: + k3d cluster delete ${CLUSTER_NAME} + +install: + helm install ${APP_NAME} ${CHART_PATH}/ + +helm-debug: + helm template ${CHART_PATH}/ --debug + +pod-debug: + kubectl describe pod + +test: + curl http://localhost:30080/api/v1/dst03106 + curl http://localhost:30080/healthcheck + From 6e60940c5e158076a1b4b4f7ca491c23eafbffef Mon Sep 17 00:00:00 2001 From: yhchae Date: Sun, 3 Aug 2025 19:06:58 +0900 Subject: [PATCH 5/9] =?UTF-8?q?perf:=20go=20=EB=B9=8C=EB=93=9C=EC=97=90=20?= =?UTF-8?q?-ldflags=3D'-s=20-w'=20=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=98=EC=97=AC=20docker=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=95=BD=202MB=20=EB=8B=A8=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/Dockerfile | 3 ++- 2025/helm/dst03106/Makefile | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/2025/helm/dst03106/Dockerfile b/2025/helm/dst03106/Dockerfile index 3452245..eedb2c1 100644 --- a/2025/helm/dst03106/Dockerfile +++ b/2025/helm/dst03106/Dockerfile @@ -1,7 +1,8 @@ FROM golang:alpine AS builder WORKDIR /app COPY main.go . -RUN go build -o main main.go +RUN go build -ldflags="-s -w" -o main main.go +# -s : (디버거를 위한) 심볼 테이블 제거, -w: 디버깅 정보 제거 FROM scratch COPY --from=builder /app/main /main diff --git a/2025/helm/dst03106/Makefile b/2025/helm/dst03106/Makefile index d081112..00c41a2 100644 --- a/2025/helm/dst03106/Makefile +++ b/2025/helm/dst03106/Makefile @@ -3,11 +3,19 @@ APP_NAME=my-app NAMESPACE=my-namespace CHART_PATH=./charts -.PHONY: docker-build create-cluster delete-cluster install helm-debug pod-debug test +.PHONY: docker-build docker-test create-cluster delete-cluster install helm-debug pod-debug test docker-build: docker build -t $(APP_NAME):latest . +docker-test: + make docker-build + docker images $(APP_NAME):latest + docker run -d -p "8000:8080" --rm --name $(APP_NAME) $(APP_NAME):latest + sleep 2 + curl http://localhost:8000/healthcheck + docker stop $(APP_NAME) + create-cluster: k3d cluster create ${CLUSTER_NAME} --port "30080:30080@loadbalancer" k3d image import ${APP_NAME}:latest -c ${CLUSTER_NAME} @@ -28,4 +36,3 @@ pod-debug: test: curl http://localhost:30080/api/v1/dst03106 curl http://localhost:30080/healthcheck - From 2dee6f9d1ee34c3c2d0c3c3bc1926ca9eaa35779 Mon Sep 17 00:00:00 2001 From: yhchae Date: Sun, 3 Aug 2025 19:25:13 +0900 Subject: [PATCH 6/9] =?UTF-8?q?chore:=20Makefile=EC=97=90=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=90=EB=8F=99=ED=99=94=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20all=20=EC=BB=A4=EB=A7=A8=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/2025/helm/dst03106/Makefile b/2025/helm/dst03106/Makefile index 00c41a2..5a8ff35 100644 --- a/2025/helm/dst03106/Makefile +++ b/2025/helm/dst03106/Makefile @@ -3,7 +3,9 @@ APP_NAME=my-app NAMESPACE=my-namespace CHART_PATH=./charts -.PHONY: docker-build docker-test create-cluster delete-cluster install helm-debug pod-debug test +.PHONY: all docker-build docker-test create-cluster delete-cluster install helm-debug pod-debug test + +all: docker-build create-cluster install test delete-cluster docker-build: docker build -t $(APP_NAME):latest . @@ -25,7 +27,7 @@ delete-cluster: k3d cluster delete ${CLUSTER_NAME} install: - helm install ${APP_NAME} ${CHART_PATH}/ + helm install ${APP_NAME} ${CHART_PATH}/ --wait helm-debug: helm template ${CHART_PATH}/ --debug From 7fac3f066c062af1c9c974d05e95edf877c19da5 Mon Sep 17 00:00:00 2001 From: yhchae Date: Fri, 22 Aug 2025 13:51:07 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20front=EA=B0=80=20=EC=9E=88=EC=9D=84?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0,=20back=20=ED=8C=8C=EB=93=9C=EC=97=90?= =?UTF-8?q?=EB=A7=8C=20=ED=8A=B8=EB=9E=98=ED=94=BD=EC=9D=B4=20=EA=B0=80?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20label,=20selector=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/charts/templates/deployment.yaml | 12 ++++++++++-- 2025/helm/dst03106/charts/templates/service.yaml | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/2025/helm/dst03106/charts/templates/deployment.yaml b/2025/helm/dst03106/charts/templates/deployment.yaml index 3059e65..9841692 100644 --- a/2025/helm/dst03106/charts/templates/deployment.yaml +++ b/2025/helm/dst03106/charts/templates/deployment.yaml @@ -4,13 +4,21 @@ metadata: name: {{ include "my-chart.fullname" . }} spec: replicas: {{ .Values.replicaCount }} - selector: + # Existing ReplicaSets whose pods are selected by this + # ... will be the ones affected by this deployment. + selector: matchLabels: app: {{ include "my-chart.name" . }} + tier: backend + matchExpressions: # ref. https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/labels/ + - {key : environment, operator: NotIn, values: [dev]} + # Template describes the pods that will be created. template: metadata: - labels: + labels: # labels과 selector는 object 타입 app: {{ include "my-chart.name" . }} + tier: backend + environment: prod spec: containers: - name: {{ .Chart.Name }} diff --git a/2025/helm/dst03106/charts/templates/service.yaml b/2025/helm/dst03106/charts/templates/service.yaml index f0a89db..2f7560f 100644 --- a/2025/helm/dst03106/charts/templates/service.yaml +++ b/2025/helm/dst03106/charts/templates/service.yaml @@ -14,3 +14,4 @@ spec: protocol: TCP selector: # 어떤 파드에 트래픽을 보낼지 라벨로 선택 app: {{ include "my-chart.name" . }} + tier: backend From 345b178433a65ee0f7e299f122faee919f35b1de Mon Sep 17 00:00:00 2001 From: yhchae Date: Fri, 22 Aug 2025 14:21:03 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20deployment.yaml=EC=97=90=EC=84=9C=20?= =?UTF-8?q?containerPort=EC=99=80=20env=EC=9D=98=20Port=EA=B0=80=20?= =?UTF-8?q?=EB=8F=99=EC=9D=BC=ED=95=9C=20=EA=B0=92=EC=9D=84=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/Dockerfile | 2 -- 2025/helm/dst03106/charts/templates/deployment.yaml | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/2025/helm/dst03106/Dockerfile b/2025/helm/dst03106/Dockerfile index eedb2c1..76d4c9b 100644 --- a/2025/helm/dst03106/Dockerfile +++ b/2025/helm/dst03106/Dockerfile @@ -7,6 +7,4 @@ RUN go build -ldflags="-s -w" -o main main.go FROM scratch COPY --from=builder /app/main /main -ENV PORT=8080 -EXPOSE 8080 ENTRYPOINT ["/main"] diff --git a/2025/helm/dst03106/charts/templates/deployment.yaml b/2025/helm/dst03106/charts/templates/deployment.yaml index 9841692..15c8295 100644 --- a/2025/helm/dst03106/charts/templates/deployment.yaml +++ b/2025/helm/dst03106/charts/templates/deployment.yaml @@ -24,6 +24,9 @@ spec: - name: {{ .Chart.Name }} image: "{{ .Values.image.name }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: PORT + value: "{{ .Values.service.targetPort }}" ports: - containerPort: {{ .Values.service.targetPort }} # 문서화용 데이터 # List of ports to expose from the container. From dc1e6be76a657c195a66bf7758a59aa5295cc562 Mon Sep 17 00:00:00 2001 From: yhchae Date: Fri, 22 Aug 2025 15:26:48 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20Dockerfile=EC=97=90=20=EC=A0=95?= =?UTF-8?q?=EC=A0=81=20=EB=A7=81=ED=81=AC=EB=A1=9C=20=EB=B9=8C=EB=93=9C?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EC=84=A4=EC=A0=95=EC=9D=84=20=EB=AA=85?= =?UTF-8?q?=EC=8B=9C=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yhchae --- 2025/helm/dst03106/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2025/helm/dst03106/Dockerfile b/2025/helm/dst03106/Dockerfile index 76d4c9b..b0fa463 100644 --- a/2025/helm/dst03106/Dockerfile +++ b/2025/helm/dst03106/Dockerfile @@ -1,7 +1,7 @@ FROM golang:alpine AS builder WORKDIR /app COPY main.go . -RUN go build -ldflags="-s -w" -o main main.go +RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o main main.go # -s : (디버거를 위한) 심볼 테이블 제거, -w: 디버깅 정보 제거 FROM scratch