시작하며
2023년 4월 한국금융연수원에서 진행된 클라우드 데이터 인프라 과정의 5일차 내용이다. Amazon Glue를 통한 데이터 통합 서비스와 EMR Glue Catalog 연동 실습, 그리고 Kubernetes와 EKS를 활용한 컨테이너 오케스트레이션 및 ECS CI/CD 파이프라인을 다룬다.

Amazon Glue와 데이터 파이프라인
Amazon Glue
AWS Glue는 분석 사용자가 여러 소스의 데이터를 쉽게 검색, 준비, 이동, 통합할 수 있도록 하는 서버리스 데이터 통합 서비스이다. 분석, 기계 학습 및 애플리케이션 개발에 사용할 수 있다. 또한 작성, 작업 실행, 비즈니스 워크플로 구현을 위한 추가 생산성 및 데이터 운영 도구도 포함된다.
AWS Glue를 사용하면 70개 이상의 다양한 데이터 소스를 검색하여 연결하고 중앙 집중식 데이터 카탈로그에서 데이터를 관리할 수 있다. 추출, 변환, 로드(ETL) 파이프라인을 시각적으로 생성, 실행, 모니터링하여 데이터 레이크에 데이터를 로드할 수 있다. 또한 Amazon Athena, Amazon EMR, Amazon Redshift Spectrum을 사용하여 카탈로그화된 데이터를 즉시 검색하고 쿼리할 수 있다.
Amazon EMR, Glue Catalog 연동 실습
wget https://aws-dojo.com/ws41/customers.csv
aws s3 cp ./customers.csv s3://glue-demo-kbi-0127/customers/
import sys
from datetime import datetime
from pyspark.sql import SparkSession
from pyspark.sql.functions import *
spark = SparkSession.builder.appName("SparkETL").getOrCreate()
spark.catalog.setCurrentDatabase("demodb")
df = spark.sql("select * from customers_csv")
df.show()
spark.catalog.setCurrentDatabase("demodb")
df = spark.sql("select * from customers_csv")
df.show()
df = df.select("CUSTOMERNAME","EMAIL")
df.show()
df.write.format("json").mode("overwrite").save(" s3://glue-demo-kbi-0127/output/")
Data-Pipeline 실습
Kubernetes와 EKS
Container, Kubernetes 입문
컨테이너:
- 운영체제 레벨의 가상화를 제공한다.
- 초단위로 올라가기 때문에 굉장히 빠르게 수정할 수 있다.
- 애플리케이션과 바이너리만을 패키징한다.
- 작은 용량, 작은 리소스, 빠른 시간이 특징이다.
OCI(Open Container Initiative)로 통일되어 관리된다.
Docker:
- 레지스트리로부터 로컬에 없는 Layer만 받아온다.
- VM은 hypervisor가 떠서 돌리지만, Container의 경우에는 각각 올라간다.
- docker에서 run은 pull + start를 의미한다.
- layer를 줄이기 위해 한 번에 만들기 위해 Dockerfile의 명령어들을
&&으로 묶어 사용한다.
Kubernetes Workshop
Kubernetes란?
Kubernetes: 쿠버네티스는 컨테이너화된 워크로드와 서비스를 관리하기 위한 이식성이 있고 확장 가능한 오픈소스 플랫폼이다. 쿠버네티스는 선언적 구성과 자동화를 모두 용이하게 해주는 컨테이너 오케스트레이션 툴이다.
-
노드들은 크게 두 가지 유형으로 나뉜다.
- 컨트롤 플레인(Control Plane)은 워커 노드와 클러스터 내 파드를 관리하고 제어한다.
- 데이터 플레인(Data Plane)은 워커 노드들로 구성되어 있으며 컨테이너화된 애플리케이션의 구성 요소인 파드를 호스트한다.
-
Kubernetes Objects:
- 쿠버네티스의 오브젝트는 바라는 상태(desired state)를 담은 레코드이다.
- 오브젝트를 생성하면 쿠버네티스의 컨트롤 플레인에서 오브젝트의 현재 상태(current state)와 바라는 상태를 일치시키기 위해 끊임없이 관리한다.
- 쿠버네티스의 오브젝트에는 파드(pod), 서비스(service), 디플로이먼트(Deployment) 등이 있다.
-
EKS 클러스터 배포 방식:
- AWS 콘솔 창에서 클릭으로 배포하는 방법
- AWS CloudFormation 혹은 AWS CDK와 같은 IaC(Infrastructure as Code) 도구를 사용해 배포하는 방법
- EKS의 공식 CLI인 eksctl로 배포하는 방법 (현재 사용중인 방식)
- Terraform, Pulumi, Rancher 등으로 배포하는 방법
- ECS를 마찬가지로 사용한다(사용할 코드)
kbi0127:~/environment $ eksctl create cluster -f eks-demo-cluster.yaml 2023-04-16 07:59:53 [!] SSM is now enabled by default; `ssh.enableSSM` is deprecated and will be removed in a future release 2023-04-16 07:59:53 [ℹ] eksctl version 0.137.0 2023-04-16 07:59:53 [ℹ] using region ap-northeast-2 2023-04-16 07:59:53 [ℹ] setting availability zones to [ap-northeast-2d ap-northeast-2b ap-northeast-2c] 2023-04-16 07:59:53 [ℹ] subnets for ap-northeast-2d - public:10.0.0.0/19 private:10.0.96.0/19 2023-04-16 07:59:53 [ℹ] subnets for ap-northeast-2b - public:10.0.32.0/19 private:10.0.128.0/19 2023-04-16 07:59:53 [ℹ] subnets for ap-northeast-2c - public:10.0.64.0/19 private:10.0.160.0/19 2023-04-16 07:59:53 [ℹ] nodegroup "node-group" will use "" [AmazonLinux2/1.23] 2023-04-16 07:59:53 [ℹ] using Kubernetes version 1.23 2023-04-16 07:59:53 [ℹ] creating EKS cluster "eks-demo" in "ap-northeast-2" region with managed nodes 2023-04-16 07:59:53 [ℹ] 1 nodegroup (node-group) was included (based on the include/exclude rules) 2023-04-16 07:59:53 [ℹ] will create a CloudFormation stack for cluster itself and 0 nodegroup stack(s) 2023-04-16 07:59:53 [ℹ] will create a CloudFormation stack for cluster itself and 1 managed nodegroup stack(s) 2023-04-16 07:59:53 [ℹ] if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=ap-northeast-2 --cluster=eks-demo' 2023-04-16 07:59:53 [ℹ] Kubernetes API endpoint access will use default of {publicAccess=true, privateAccess=false} for cluster "eks-demo" in "ap-northeast-2" 2023-04-16 07:59:53 [ℹ] configuring CloudWatch logging for cluster "eks-demo" in "ap-northeast-2" (enabled types: api, audit, authenticator, controllerManager, scheduler & no types disabled) 2023-04-16 07:59:53 [ℹ] 2 sequential tasks: { create cluster control plane "eks-demo", 2 sequential sub-tasks: { 4 sequential sub-tasks: { wait for control plane to become ready, associate IAM OIDC provider, 2 sequential sub-tasks: { create IAM role for serviceaccount "kube-system/aws-node", create serviceaccount "kube-system/aws-node", }, restart daemonset "kube-system/aws-node", }, create managed nodegroup "node-group", } } 2023-04-16 07:59:53 [ℹ] building cluster stack "eksctl-eks-demo-cluster" 2023-04-16 07:59:54 [ℹ] deploying stack "eksctl-eks-demo-cluster" 2023-04-16 08:00:24 [ℹ] waiting for CloudFormation stack "eksctl-eks-demo-cluster" -
Kubernetes AutoScaling:
- HPA(Horizontal Pod AutoScaler): CPU 사용량 또는 사용자 정의 메트릭을 관찰하여 파드 개수를 자동으로 스케일한다.
- Cluster Autoscaler: 클러스터 수준에서 노드를 자동으로 스케일한다.
ECS + CI/CD Workshop
- ECS Workshop Result
- cluster auto-scaling
- ci/cd - codepipeline
정리하며
5일차에서는 Amazon Glue를 활용한 서버리스 데이터 통합과 EMR Glue Catalog 연동 실습을 진행했다. 이어서 컨테이너와 Docker의 핵심 개념을 정리하고, Kubernetes(EKS)를 통한 컨테이너 오케스트레이션 및 ECS 기반 CI/CD 파이프라인 구성을 워크숍 형태로 실습했다. 클라우드 네이티브 데이터 플랫폼 구성에서 컨테이너 오케스트레이션은 핵심적인 역할을 담당한다.