Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions .github/workflows/build-and-update-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Update Manifest

on:
push:
branches: [ "cicd_test" ]
paths: [ "app/**", "Dockerfile", "k8s/**" ]

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: eu-west-1

- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and Push Image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/data-pipeline-app:$IMAGE_TAG .
docker push $ECR_REGISTRY/data-pipeline-app:$IMAGE_TAG

- name: Update Kustomize Tag
run: |
cd k8s/overlays/prod
kustomize edit set image data-pipeline-app=${{ steps.login-ecr.outputs.registry }}/data-pipeline-app:${{ github.sha }}

- name: Commit and Push Manifest Change
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "github-actions"
git add k8s/overlays/prod/kustomization.yaml
git commit -m "Update image tag to ${{ github.sha }} [skip ci]"
git push origin cicd_test
67 changes: 0 additions & 67 deletions .github/workflows/cd.yaml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/ci.yaml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI/CD Pipeline with Canary Deployment

on:
push:
branches: [ "main" ]

env:
AWS_REGION: eu-west-1
ECR_REPOSITORY: data-pipeline-app
KUBE_NAMESPACE: default

jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::123456789012:role/GitHubActionsEKSRole # 생성한 IAM Role ARN 입력
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Setup Kubeconfig
run: |
aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name my-eks-cluster # 실제 클러스터 명으로 변경

- name: Install Kustomize
uses: imranismail/setup-kustomize@v2

- name: Deploy v2 App to EKS
env:
IMAGE_TAG: ${{ github.sha }}
run: |
cd k8s/overlays/v2
kustomize edit set image data-pipeline-app=123456789012.dkr.ecr.eu-west-1.amazonaws.com/data-pipeline-app:$IMAGE_TAG
kustomize build . | kubectl apply -f -
kubectl rollout status deployment/data-pipeline-app-v2 -n ${{ env.KUBE_NAMESPACE }} --timeout=120s

- name: Apply Canary Ingress (v1: 90%, v2: 10%)
env:
WEIGHT_V1: 90
WEIGHT_V2: 10
run: |
envsubst < k8s/ingress/ingress.yaml | kubectl apply -f -
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Terraform
.terraform/
*.tfstate
*.tfstate.backup
*.tfvars
.terraform.lock.hcl

# IDE
.idea/
.vscode/

# Python
__pycache__/
*.pyc
4 changes: 2 additions & 2 deletions k8s/argocd/app-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
spec:
project: default
source:
repoURL: https://github.com/yooseongjin527/asac_de2_infra_1st
targetRevision: cicd
repoURL: https://github.com/masondev1024/my-data-platform
targetRevision: cicd_test
path: k8s/overlays/prod
destination:
server: https://kubernetes.default.svc
Expand Down
4 changes: 2 additions & 2 deletions k8s/base/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ spec:
spec:
containers:
- name: draw-worker
image: 486053612615.dkr.ecr.eu-west-2.amazonaws.com/my-raffle-app:v1
image: 486053612615.dkr.ecr.eu-west-1.amazonaws.com/my-raffle-app:v1
command: ["python", "draw_winner.py"]
envFrom:
- configMapRef:
name: raffle-config
- secretRef:
name: raffle-secret
restartPolicy: OnFailure
restartPolicy: OnFailure
27 changes: 0 additions & 27 deletions k8s/base/deployment.yaml

This file was deleted.

26 changes: 3 additions & 23 deletions k8s/base/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: raffle-hpa-v1
name: data-pipeline-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: raffle-app-v1
minReplicas: 2
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
---
# V2 오토스케일러
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: raffle-hpa-v2
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: raffle-app-v2
kind: Rollout
name: data-pipeline-app
minReplicas: 2
maxReplicas: 20
metrics:
Expand Down
12 changes: 4 additions & 8 deletions k8s/base/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: raffle-ingress
name: data-pipeline-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
# 카나리아 가중치 설정 (현재 v1: 100%, v2: 0%)
alb.ingress.kubernetes.io/actions.canary-routing: >
{"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"raffle-svc-v1","servicePort":"80","weight":100},{"serviceName":"raffle-svc-v2","servicePort":"80","weight":0}]}}
spec:
ingressClassName: alb
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: canary-routing
port:
name: use-annotation
name: data-pipeline-svc-stable
port: { number: 80 }
40 changes: 40 additions & 0 deletions k8s/base/karpenter-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 1. 어떤 사양의 EC2를 띄울 것인가? (인프라 설정)
apiVersion: karpenter.k8s.aws/v1beta1
kind: EC2NodeClass
metadata:
name: default
spec:
amiFamily: AL2023 # 최신 Amazon Linux 2023 사용
role: EKSNodeRole # 테라폼에서 생성한 노드 역할 이름과 일치해야 함
subnetSelectorTerms:
- tags:
karpenter.sh/discovery: "data-engineer-cluster"
securityGroupSelectorTerms:
- tags:
kubernetes.io/cluster/data-engineer-cluster: "owned"
---
# 2. 어떤 조건에서 노드를 늘릴 것인가? (스케일링 정책)
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
name: default
spec:
template:
spec:
requirements:
- key: kubernetes.io/arch
operator: In
values: ["amd64"]
- key: karpenter.sh/capacity-type
operator: In
values: ["on-demand", "spot"] # 비용 절감을 원하면 spot 포함
- key: node.kubernetes.io/instance-type
operator: In
values: ["t3.medium", "c5.large"] # 필요한 인스턴스 사양 정의
nodeClassRef:
name: default
limits:
cpu: 100 # 전체 클러스터의 최대 CPU 제한
disruption:
consolidationPolicy: WhenUnderutilized
expireAfter: 720h # 30일 후 노드 교체 (보안 업데이트 등 방어용)
Loading
Loading