Terraform 으로 EKS 배포
첫 번째 EKS 클러스터 배포
- git clone 및 terraform init → plan → apply
# 코드 가져오기
git clone https://github.com/gasida/aews-cicd.git
cd aews-cicd/4
# terraform 환경 변수 저장
export TF_VAR_KeyName=kp-ihwoo
echo $TF_VAR_KeyName
#
terraform init
terraform plan
# 10분 후 배포 완료
terraform apply -auto-approve
- 주요 생성 자원 : VPC, Subnet, IGW, NATGW, Routing Table, EKS, EKS SG
- 테라폼 정보 확인
#
terraform state list
#
terraform console
#
cat terraform.tfstate | jq
more terraform.tfstate
- 배포 정보 확인
# EKS 클러스터 인증 정보 업데이트
CLUSTER_NAME=myeks
aws eks update-kubeconfig --region ap-northeast-2 --name $CLUSTER_NAME
kubectl config rename-context "arn:aws:eks:ap-northeast-2:$(aws sts get-caller-identity --query 'Account' --output text):cluster/$CLUSTER_NAME" "Aews-Labs"
#
kubectl cluster-info
kubectl get node --label-columns=node.kubernetes.io/instance-type,eks.amazonaws.com/capacityType,topology.kubernetes.io/zone
kubectl get pod -A
두 번째 EKS 클러스터 베포 : 코드 재사용 검증
- 새로 만든 디렉토리에 기존 tf 파일 복사 및 terraform init → plan → apply
#
terraform init
terraform apply -auto-approve -var=ClusterBaseName=myeks2 -var=KubernetesVersion="1.28"
# EKS 클러스터 인증 정보 가져오기
CLUSTER_NAME2=myeks2
aws eks update-kubeconfig --region ap-northeast-2 --name $CLUSTER_NAME2 --kubeconfig ./myeks2config
# EKS 클러스터 정보 확인
kubectl --kubeconfig ./myeks2config get node
kubectl --kubeconfig ./myeks2config get pod -A
'Kubernetes > AWS EKS Workshop Study' 카테고리의 다른 글
8주차 2편 EKS IaC - Terraform, VPC, EC2 (0) | 2024.04.28 |
---|---|
8주차 1편 EKS IaC - Terraform, HCL (1) | 2024.04.28 |
7주차 2편 EKS CI/CD - Jenkins with Kubernetes, Argo (1) | 2024.04.21 |
7주차 1편 EKS CI/CD - Docker, Jenkin (0) | 2024.04.21 |