05 AWS Fargate 사용하기

shin·2023년 6월 14일
0

Kubernetes

목록 보기
8/12

Amazon EKS로 웹 애플리케이션 구축하기

AWS Fargate 란 ?

  • 컨테이너에 적합한 서버리스 컴퓨팅 엔진
  • 서버를 프로비저닝하고 관리할 필요가 없어 애플리케이션별로 리소스를 지정하고 관련 비용을 지불할 수 있음
  • 계획적으로 애플리케이션을 격리함으로써 보안 성능을 향상시킬 수 있음

1) AWS Fargate로 pod 배포

  • 클러스터에 Fargate로 pod를 배포하기 위해서는 pod가 실행될 때 사용하는 하나 이상의 fargate profile을 정의해야 함
    • fargate profile : fargate로 pod를 생성하기 위한 조건을 명시해놓은 프로파일
cd /home/ec2-user/environment/manifests
cat <<EOF> eks-demo-fargate-profile.yaml
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: eks-demo
  region: ${AWS_REGION}
fargateProfiles:
  - name: frontend-fargate-profile
    selectors:
      - namespace: default
        labels:
          app: frontend-fargate
EOF
  • fargate profile 프로비저닝
eksctl create fargateprofile -f eks-demo-fargate-profile.yaml               

  • fargate profile이 정상적으로 생성되었는지 확인
eksctl get fargateprofile --cluster eks-demo -o json

  • 이전 서비스 배포하기 단계에서 배포한 3개의 pod 중, frontend pod를 fargate로 프로비저닝하는 작업을 수행
    • 기존의 pod를 삭제
kubectl delete -f frontend-deployment.yaml 
  • frontend-deployment.yaml 파일 수정
    • label의 value 값을 frontend-fargate로 변경
cd /home/ec2-user/environment/manifests

cat <<EOF> frontend-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-frontend
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: frontend-fargate
  template:
    metadata:
      labels:
        app: frontend-fargate
    spec:
      containers:
        - name: demo-frontend
          image: $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/demo-frontend:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 80
EOF
  • frontend-service.yaml 파일도 수정
cat <<EOF> frontend-service.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: demo-frontend
  annotations:
    alb.ingress.kubernetes.io/healthcheck-path: "/"
spec:
  selector:
    app: frontend-fargate
  type: NodePort
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
EOF
  • 매니페스트 배포
kubectl apply -f frontend-deployment.yaml
kubectl apply -f frontend-service.yaml
  • pod 리스트를 확인해보면 demo-frontend pod의 경우 fargate-ip-xx 노드에 프로비저닝되었음을 확인할 수 있음
  • 혹은 아래 명령어로 Fargate worker nodes 리스트를 확인할 수 있음
  • 아래 명령어 수행 결과를 웹 브라우저에 붙여 넣으면 이전과 같은 화면 확인 가능

profile
Backend development

0개의 댓글