클라우드 eks 배포 가이드 - 100-hours-a-week/16-Hot6-wiki GitHub Wiki

EKS 애플리케이션 시크릿, 환경 변수, Ingress 주입 및 배포 가이드

  1. 개요: GitOps 기반 애플리케이션 배포 및 시크릿 관리 이 문서는 EKS 클러스터에서 onthetop-backend 애플리케이션을 배포하고, 필요한 민감한 시크릿 값(secrets.properties)과 비민감 환경 변수를 안전하고 자동화된 방식으로 주입하며, 외부로 노출하는 전체 과정을 설명합니다. 모든 설정은 Git에 코드로 관리되며, Argo CD가 이를 클러스터에 자동으로 동기화하는 GitOps 워크플로우를 따릅니다.

핵심 목표: 보안 강화: 민감한 정보(비밀번호)는 Git에 노출되지 않고 AWS Secrets Manager에 안전하게 보관.

자동화: 애플리케이션 배포, 업데이트, 시크릿/환경 변수 주입이 모두 자동화.

일관성: 모든 구성이 Git에 코드로 관리되어 환경 간 일관성 유지 및 재현성 확보.

외부 노출: ALB Ingress Controller를 통해 애플리케이션을 외부 도메인으로 노출.

  1. 전체 아키텍처 및 데이터 흐름 우리가 구축한 시스템은 다음과 같은 구성 요소들이 유기적으로 연결되어 작동합니다.

AWS Secrets Manager: 민감한 시크릿(비밀번호)의 중앙 저장소.

Git 리포지토리: 모든 Kubernetes 리소스(Deployment, Service, Ingress, ExternalSecret, ConfigMap) 정의가 코드로 저장되는 곳. (Single Source of Truth)

Argo CD: Git 리포지토리의 상태를 EKS 클러스터에 자동으로 동기화하는 GitOps 도구.

External Secrets Operator (ESO): AWS Secrets Manager에서 실제 시크릿 값을 가져와 Kubernetes Secret으로 만들어주는 역할.

Kubernetes 클러스터 (EKS): 애플리케이션 Pod들이 실행되는 환경.

ClusterSecretStore: ESO가 AWS Secrets Manager와 통신하기 위한 연결 설정 (Terraform으로 미리 배포).

Secret: ESO에 의해 생성된 Kubernetes의 기본 시크릿 리소스.

ConfigMap: 비민감 환경 변수들이 저장되는 Kubernetes 리소스.

Deployment / Pod: 애플리케이션 컨테이너가 실행되며, Secret과 ConfigMap의 데이터를 주입받아 사용.

AWS Application Load Balancer (ALB): Ingress를 통해 프로비저닝되며, 외부 트래픽을 EKS 클러스터 내부의 서비스로 라우팅.

  1. 시크릿 값 주입 (secrets.properties 파일) onthetop-backend 애플리케이션의 secrets.properties 파일 내용을 AWS Secrets Manager에 저장하고, 이를 Pod에 파일 형태로 주입하는 과정입니다.

3.1. AWS Secrets Manager에 시크릿 저장 secrets.properties 파일의 내용을 AWS Secrets Manager에 onthetop/backend/secrets-properties라는 이름의 시크릿으로 저장합니다. 이 값은 Git에 절대 노출되지 않습니다.

예시 (AWS CLI):

aws secretsmanager create-secret
--name onthetop/backend/secrets-properties
--secret-string file://./secrets.properties
--region ap-northeast-2

3.2. ExternalSecret 정의 (Git 리포지토리) 파일: application-gitops-repo/kubernetes/onthetop-backend/external-secret.yaml

역할: ESO에게 AWS Secrets Manager에서 특정 시크릿을 가져와 Kubernetes Secret으로 만들라고 지시합니다.

코드:

apiVersion: external-secrets.io/v1beta1 kind: ExternalSecret metadata: name: onthetop-backend-secrets # ESO가 생성할 Kubernetes Secret의 이름 namespace: onthetop-backend # ExternalSecret 및 생성될 Secret이 위치할 네임스페이스 spec: refreshInterval: "1h" # AWS Secrets Manager에서 값 동기화 주기 secretStoreRef: name: aws-secrets-manager-cluster-store # Terraform으로 배포된 ClusterSecretStore 이름 kind: ClusterSecretStore target: name: onthetop-backend-secrets # Kubernetes Secret의 이름 (ExternalSecret의 이름과 동일) creationPolicy: Owner # ExternalSecret 삭제 시 Kubernetes Secret도 삭제 template: data: secrets.properties: "{{ .secrets_properties_file_content }}" # AWS Secrets Manager 값을 secrets.properties 키로 저장 data: - secretKey: secrets_properties_file_content # AWS Secrets Manager 값의 임시 키 remoteRef: key: onthetop/backend/secrets-properties # AWS Secrets Manager의 실제 시크릿 이름 # property: (secrets.properties가 JSON이 아니라면 이 줄은 제거)

동작: Argo CD가 이 파일을 클러스터에 적용하면, ESO는 aws-secrets-manager-cluster-store를 통해 AWS Secrets Manager에서 onthetop/backend/secrets-properties 값을 가져와 onthetop-backend-secrets라는 Kubernetes Secret을 생성합니다.

3.3. Deployment에서 시크릿 파일 마운트 파일: application-gitops-repo/kubernetes/onthetop-backend/deployment.yaml

역할: ESO가 생성한 onthetop-backend-secrets Kubernetes Secret을 Pod의 컨테이너 내부에 /app/secrets.properties 파일로 마운트합니다.

코드 (관련 부분):

Deployment YAML 내

volumeMounts:

  • name: secrets-properties-volume mountPath: "/app/secrets.properties" # 컨테이너 내부에서 파일이 마운트될 경로 subPath: "secrets.properties" # Secret 내의 'secrets.properties' 키를 파일 이름으로 사용 readOnly: true volumes:
  • name: secrets-properties-volume secret: secretName: onthetop-backend-secrets # ESO가 생성한 Secret 이름 args:
  • "--spring.config.additional-location=file:/app/secrets.properties" # 애플리케이션이 마운트된 파일 읽도록 지시

동작: Pod가 시작될 때 secrets.properties 파일이 /app/secrets.properties 경로에 주입되고, 애플리케이션은 이 파일을 설정으로 읽어 사용합니다.

  1. 환경 변수 주입 민감하지 않은 환경 변수(BE_VERSION, PORT 등)는 ConfigMap을 통해 주입합니다.

4.1. ConfigMap 정의 (Git 리포지토리) 파일: application-gitops-repo/kubernetes/onthetop-backend/configmap.yaml

역할: 비민감 환경 변수들을 키-값 형태로 정의합니다.

코드:

apiVersion: v1 kind: ConfigMap metadata: name: onthetop-backend-config # ConfigMap의 이름 namespace: onthetop-backend # ConfigMap이 위치할 네임스페이스 data: BE_VERSION: "v2.0.3" # Docker 이미지 태그 PORT: "8080" # 애플리케이션 포트

4.2. Deployment에서 환경 변수 주입 파일: application-gitops-repo/kubernetes/onthetop-backend/deployment.yaml

역할: onthetop-backend-config ConfigMap의 값을 컨테이너의 환경 변수로 주입합니다.

코드 (관련 부분):

Deployment YAML 내

env:

  • name: SPRING_PROFILES_ACTIVE value: "prod"
  • name: PORT # ConfigMap에서 가져옴 valueFrom: configMapKeyRef: name: onthetop-backend-config key: PORT
  • name: BE_VERSION # ConfigMap에서 가져옴 valueFrom: configMapKeyRef: name: onthetop-backend-config key: BE_VERSION

... 기타 환경 변수 ...

동작: Pod가 시작될 때 PORT, BE_VERSION 등의 환경 변수가 설정됩니다.

  1. 애플리케이션 외부 노출 (Ingress) 애플리케이션을 외부 인터넷에 노출시키기 위해 Ingress를 사용하며, 기존 Argo CD Ingress와 동일한 ALB를 공유합니다.

5.1. Service 정의 (Git 리포지토리) 파일: application-gitops-repo/kubernetes/onthetop-backend/service.yaml

역할: Deployment의 Pod들을 그룹화하고 클러스터 내부에서 접근 가능한 고정된 네트워크 엔드포인트를 제공합니다. Ingress가 이 서비스를 통해 트래픽을 Pod로 보냅니다.

코드:

apiVersion: v1 kind: Service metadata: name: onthetop-backend-service # 서비스 이름 (Ingress에서 참조) namespace: onthetop-backend # 서비스가 배포될 네임스페이스 labels: app: onthetop-backend # Deployment의 라벨과 일치 spec: selector: app: onthetop-backend # Deployment의 Pod를 선택 ports: - protocol: TCP port: 80 # 서비스가 노출할 포트 (Ingress가 이 포트로 통신) targetPort: 8080 # 파드 컨테이너의 실제 포트 type: ClusterIP # 클러스터 내부에서만 접근 가능

5.2. Ingress 정의 (Git 리포지토리) 파일: application-gitops-repo/kubernetes/onthetop-backend/ingress.yaml

역할: 외부 HTTP/HTTPS 트래픽을 onthetop-backend-service로 라우팅하는 규칙을 정의하고, AWS Application Load Balancer (ALB)를 프로비저닝/설정합니다.

ALB 공유: alb.ingress.kubernetes.io/group.name: onthetop-services 어노테이션을 통해 기존 argocd-ingress와 동일한 ALB를 공유합니다.

코드:

apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: onthetop-backend-ingress namespace: onthetop-backend annotations: kubernetes.io/ingress.class: alb alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: ip alb.ingress.kubernetes.io/group.name: onthetop-services # Argo CD와 동일한 ALB 그룹 이름 alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]' alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}' alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-northeast-2:514883192355:certificate/f3093065-c635-4a0c-882e-416f5a4dea97 alb.ingress.kubernetes.io/backend-protocol: HTTP alb.ingress.kubernetes.io/healthcheck-path: /healthz # 실제 애플리케이션 헬스체크 경로 alb.ingress.kubernetes.io/healthcheck-protocol: HTTP alb.ingress.kubernetes.io/success-codes: '200,307' spec: ingressClassName: alb rules: - host: eks-backend.onthe-top.com # 애플리케이션 도메인 http: paths: - path: / pathType: Prefix backend: service: name: onthetop-backend-service # 트래픽을 보낼 Kubernetes Service 이름 port: number: 80 # Service가 노출하는 포트

ALB 동작: aws-load-balancer-controller는 이 Ingress 정의를 감지하여 onthetop-services ALB에 eks-backend.onthe-top.com 호스트에 대한 라우팅 규칙을 추가하고, 트래픽을 onthetop-backend-service로 보냅니다.

  1. GitOps 워크플로우 (Argo CD를 통한 배포) 모든 Kubernetes 리소스 정의는 Git에 저장되고, Argo CD가 이 Git 상태를 클러스터에 자동으로 동기화합니다.

6.1. Git 리포지토리 푸시 위에서 정의된 모든 YAML 파일들(namespace.yaml, external-secret.yaml, configmap.yaml, deployment.yaml, service.yaml, ingress.yaml)을 application-gitops-repo의 kubernetes/onthetop-backend 경로에 커밋하고 푸시합니다.

6.2. Argo CD Application 정의 파일: argocd-config-repo/applications/onthetop-backend.yaml

역할: Argo CD에게 application-gitops-repo를 모니터링하고 EKS 클러스터에 동기화하라고 지시합니다.

코드:

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: onthetop-backend # Argo CD 애플리케이션 이름 namespace: argocd # Argo CD가 설치된 네임스페이스 spec: project: default source: repoURL: https://github.com/your-org/application-gitops-repo.git # 당신의 Git 리포지토리 URL targetRevision: HEAD # Git 브랜치 또는 태그 path: kubernetes/onthetop-backend # YAML 파일들이 있는 경로 destination: server: https://kubernetes.default.svc namespace: onthetop-backend # 애플리케이션이 배포될 네임스페이스 syncPolicy: automated: prune: true selfHeal: true syncOptions: - CreateNamespace=true # 네임스페이스 자동 생성

6.3. 자동 동기화 및 배포 Argo CD는 Git 리포지토리의 변경 사항을 감지하고 클러스터에 자동으로 동기화합니다.

onthetop-backend 네임스페이스 생성.

onthetop-backend-config ConfigMap 생성.

onthetop-backend-secrets ExternalSecret 생성.

ESO가 ExternalSecret을 감지하여 AWS Secrets Manager에서 시크릿 값을 가져와 onthetop-backend-secrets Kubernetes Secret 생성.

onthetop-backend-service 생성.

onthetop-backend-ingress 생성 (ALB 업데이트).

onthetop-backend-app Deployment 배포 (Pod 실행, Secret과 ConfigMap 주입).

  1. 결론 이 GitOps 기반의 배포 및 시크릿 관리 방식은 onthetop-backend 애플리케이션의 보안, 자동화, 일관성 및 운영 효율성을 크게 향상시킵니다. 모든 구성이 코드로 명확하게 정의되어 있으므로, 동료들과의 협업 및 문제 해결에도 큰 도움이 될 것입니다.