EKS 기반의 쿠버네티스 클러스터를 생성할때 AWS 콘솔로 하는 경우도 있지만
테라폼을 활용하여 Iac 스타일로 구성할 수도 있다.
테라폼 코드를 개인 로컬 PC에서 관리하여 EKS를 구축할수도 있지만
GitHub에 테라폼 코드, Helm 차트 및 k8s 등을 push 할수도 있다.
이렇게 쿠버네티스 구성 요소 들을 GitHub에 배포할 경우 ArgoCD 서비스와 연동하여 CD(Continuous Deployment) 환경 또한 구성 가능하다.
우선 깃허브에 생성할 레포지토리는 아래와 같다.
gitops-repository
-나머지 Repository를 제어,실행을 위한 코드 관리
platform-repository
-플랫폼 및 Kubernetes 프로비저닝을 위한 IaC 코드 관리
management-repository
-Kubernetes 관리를 위한 설정,플러그인,시스템 배포 코드 관리
service-repository
-컨테이너 기반의 서비스 앱개발 소스 코드 관리
테라폼 코드 및 쿠버네티스 구성 요소를 배포하고 편집할 로컬 PC와 GitHub를 연동한다.
연동에 필요한 절차 및 명령어는 아래와 같다
- 깃허브 SSH 인증키 생성
$ cd ~
$ ssh-keygen -t ed25519 -C "<본인 깃허브 로그인 메일주소>"
본인 깃허브에 로그인 하여 settings > SSH and GPG keys 메뉴에서 인증키를 SSH key로 등록한다.
Tiile 부분은 임의로 설정할 수 있으며 Key type은 Authentication Key로 하고
Key 내용은 public key(id_ed25519.pub) 내용을 붙여넣는다
이번 포스트에서는 테라폼을 통해 EKS를 생성할 예정이며 앞서 설명한 레포지토리에 관련 코드를 push했으며, 로컬 PC 에서 아래와 같이 테스트 디렉터리를 생성 했다.
# terraform-backend/iac.tf 파일
module "terraform-backend" {
source = "git@github.com:<GitHub 유저명>/platform-repository/platform-repository.git//aws/ap-northeast-2/terraform-backend?ref=main"
}
# terraform-codes/iac.tf 파일
module "terraform-codes" {
source = "git@github.com:<GitHub 유저명>/platform-repository/platform-repository.git//aws/ap-northeast-2/terraform-codes?ref=main"
}
terrform init 명령어 수행 시 아래와 같이 결국 GitHub 레포지토리 중 platform-repository 테라폼 코드를 실행하게 된다.