본문 바로가기

k8s 실전 프로젝트/1. EKS 환경구축

2. EKS 클러스터 구축

# EKS 클러스터 구축

1. 이전에 CloudFormation에서 생성한 VPC 환경정보를 활용하여 EKS 클러스터를 구축한다.

- WorkerSubnet 정보가 필요하므로 해당 WorkerSubnet 정보를 복사하여 저장해 둔다.

* eksctl 설치 → gitbash 에서 설치가 안되므로... 동일한 VPC 안에 EC2 인스턴스를 1개 생성하여 설치를 진행해보자. 이 생성된 EC2 인스턴스가 EKS 워크샵에 있는 Cloud9 역할을 한다고 보면 된다.

- EC2 인스턴스를 생성 후 아래와 같이 진행 한다. 단, EC2 인스턴스는 이전에 생성한 VPC(eks-work-VPC) 내에 존재 해야 한다.

- aws configure를 통해 사용자 인증을 한다. (aws cli 설치 필요, 인증이 완료되면 아래와 같이 설정 된다.)

- EC2 인스턴스 생성 후 eksctl version 으로 버전 조회

- Download and extract the latest release of eksctl with the following command.

curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp

- Move the extracted binary to /usr/local/bin.

sudo mv /tmp/eksctl /usr/local/bin

- Test that your installation was successful with the following command.

eksctl version

2. eksctl 실행

- 쉘 프로그램에서 아래의 명령어를 입력하면 클러스터가 구축이 된다.

WorkerSubnet 부분에는 위에서 복사한 값을 넣어주면 된다.

eksctl create cluster \
--vpc-public-subnets subnet1-********5376984,subnet2-********e98242e0f,subnet3-*******5ac771dc7b0 \
--name eks-work-cluster \
--region ap-northeast-2 \
--version 1.21 \
--nodegroup-name eks-work-nodegroup \
--node-type t2.small \
--nodes 2 \
--nodes-min 2 \
--nodes-max 5

- 다른 방법의 eksctl 배포 파일 생성

배포 파일명 : eksworkshop.yaml

cat << EOF > eksworkshop.yaml
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: eksworkshop-eksctl
  region: ${AWS_REGION}
  version: "1.17"

managedNodeGroups:
- name: nodegroup
  desiredCapacity: 3
  ssh:
    allow: true
    publicKeyName: eksworkshop

# To enable all of the control plane logs, uncomment below:
# cloudWatch:
#  clusterLogging:
#    enableTypes: ["*"]

secretsEncryption:
  keyARN: ${MASTER_ARN}
EOF

- 위의 파일로 eksctl cluster 생성

eksctl create cluster -f eksworkshop.yaml

- 자세한 내용은 아래의 글 참조

2021.10.03 - [혼자하는 프로젝트/AWS EKS + Wordpress] - Cloud9 + EKS + Wordpress 구성하기

 

Cloud9 + EKS + Wordpress 구성하기

1. Cloud9 환경구성 2021.10.03 - [AWS/Cloud9] - Cloud9 생성 및 터미널 접속 Cloud9 생성 및 터미널 접속 - cloud9을 검색하여 새로운 환경을 만든다. - 이름과 간단한 설명을 입력 후 다음으로 넘어간다. - 아..

may9noy.tistory.com

- 클러스터 구축 화면, 환경 구축에는 약 20여분이 소요된다.

- 클라우드 포메이션에서 생성작업 확인 (생성이 진행되고 있는 모습)

3. kubectl 설치

- 설치중 아래와 같이 오류가 발생 하였다. 오류 내용을 보니 kubectl을 설치 하지 못한것으로 보이고 일정 버전이 필요하다는 메세지인것 같다.

- 일반적인 명령어로는 설치가 불가능 하고 옵션으로 --classic 을 붙여줘야 설치가 가능하다.

sudo snap install kubectl --classic

- kubectl get nodes로 노드를 확인해보면 아래와같이 2개의 노드를 확인 할 수 있다.