DEV Community

Thomas Kim
Thomas Kim

Posted on

3 2

AWS EKS with eksctl

AWS 에 EKS 생성을 위한 가장 손쉬운 방법은 eksctl 을 사용하는 것이다. 그리고 eksctl cli를 실행시킬 환경은 laptop 보다는 AWS 에 bastion 서버를 만들어서 그곳에서 실행하는걸 추천한다. (laptop 에 이런 저런 환경을 옮겨가면서 작업하다보면 실수한다. 그리고 관리도 힘들다)

AWS User 생성

우선 AWS IAM 에서 programatically 사용가능하도록 admin user를 만들고 해당 user 의 AWS Access Key ID 및 AWS Secret Access Key를 획득한다.


Bastion 서버 생성

그리고 AWS에 bastion 서버를 만들자. instance type은 t3.small 이어도 충분하다. (free tier 도 상관없다) 그리고 적절히 security group 을 만들어서 서버로 들어간다.


kubectl 설치

원하는 kubernetes 버전의 kubectl 설치
https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html

$ curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
$ echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
$ kubectl version --short --client
Enter fullscreen mode Exit fullscreen mode

aws cli 설치

eksctl 을 사용하려면 AWS user의 credentil 설정이 필요하다. aws cli 를 설치한다.
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

$ sudo apt install unzip
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Enter fullscreen mode Exit fullscreen mode

aws cli configuration 설정

이제 aws cli 에 configuration 을 설정한다. 이때 위에서 획득한 credential을 사용한다. region 은 Seoul(ap-northeast-2)을 사용
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html

$ aws configure
AWS Access Key ID [None]: ~~~
AWS Secret Access Key [None]: ~~~
Default region name [None]: ap-northeast-2
Default output format [None]: json
Enter fullscreen mode Exit fullscreen mode

eksctl cli 설치

eksctl cli 를 설치한다.
https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html

$ curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
$ sudo mv /tmp/eksctl /usr/local/bin
$ eksctl version
Enter fullscreen mode Exit fullscreen mode

EKS Cluster 생성

eksctl cli로 EKS Cluster 를 생성한다.

$ eksctl create cluster \
--version 1.21 \
--name eks-demo \
--vpc-nat-mode HighlyAvailable \
--node-private-networking \
--region ap-northeast-2 \
--node-type t3.medium \
--nodes 2 \
--with-oidc \
--ssh-access \
--ssh-public-key thomas \
--managed
Enter fullscreen mode Exit fullscreen mode
  • version: 사용할 Kubernetes 버전
  • vpc-nat-mode: kubernetes의 모든 outbound는 nat gateway를 통해 나가게 되는게 default option 은 single 이라 하나만 생성된다. 개발 환경에서는 상관없을거 같지만 운영에서는 각 subnet 마다 하나씩 만드는 HighAvailable 옵션을 사용한다.
  • node-private-networking: 해당 option 이 없으면 node group 이 public subnet 에 만들어진다. 보안을 위해 private subnet 에 만들어지도록 이 옵션을 사용한다.
  • node-type: 생성될 node의 instance 타입
  • nodes: 생성 될 node의 갯수

cluster 가 잘 생성되었는지 확인한다

$ kubectl get nodes -o wide
Enter fullscreen mode Exit fullscreen mode

EKS 보안 관련 설정

여기까지 하면 상용에서 사용할 수 있도록 HA를 고려한 secure 한 방법으로 Kubernets cluster 가 생성된다. 하지만 보안을 위해 한가지를 더 해주어야 한다. 현재 상태는 cluster endpoint가 public 하게 허용되어 있다.
https://aws.amazon.com/blogs/containers/de-mystifying-cluster-networking-for-amazon-eks-worker-nodes/
https://docs.aws.amazon.com/eks/latest/userguide/cluster-endpoint.html

이를 제약하기 위해 private access 를 허용하고 CIDR 블록 제한으로 bastion 서버에서만 kubernetes 에 명령을 내릴 수 있도록 수정한다. bastion server의 Public IPv4 address 를 입력한다.

$ eksctl utils update-cluster-endpoints --cluster=eks-demo --private-access=true --public-access=true --approve
$ eksctl utils set-public-access-cidrs --cluster=eks-demo 1.1.1.1/32 --approve
Enter fullscreen mode Exit fullscreen mode

1.1.1.1/32 는 bastion 서버의 주소를 넣는다.

사실 EKS Cluster 생성 작업은 eksctl의 --dry-run 옵션으로 yaml 파일을 만들어서 생성부터 EKS 보안 관련 설정까지 모두 옵션을 주고 한번에 만들 수도 있다.


이제 이렇게 생성된 EKS Cluster 에 Istio를 설치하고 서비스를 deploy하면 바로 사용 가능하다.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up