Contents

[AWS EKS] 3. EKS Cluster ์ƒ์„ฑํ•˜๊ธฐ

Amazon EKS ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์ถ•ํ•˜๊ธฐ ์›Œํฌ์ˆ ์‹ค์Šต

โ˜๏ธ Amazon EKS ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์ถ•ํ•˜๊ธฐ ์›Œํฌ์ƒต์„ ์‹ค์Šตํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

Amazon EKS ํด๋Ÿฌ์Šคํ„ฐ๋Š” ๋‹ค์–‘ํ•œ ๋ฐฉ์‹์œผ๋กœ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค.

  • AWS ์ฝ˜์†” ์ฐฝ์œผ๋กœ ๋ฐฐํฌ
  • AWS CloudFormation ํ˜น์€ AWS CDK ์™€ ๊ฐ™์€ IaC(Infrastructure as Code) ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฐฐํฌ
  • EKS์˜ ๊ณต์‹ CLI์ธ eksctl ๋กœ ๋ฐฐํฌ
  • Terraform, Pulumi, Rancher ๋“ฑ์œผ๋กœ ๋ฐฐํฌ

eksctl๋กœ Cluster ์ƒ์„ฑํ•˜๊ธฐ

์•„๋ฌด ์˜ต์…˜์—†์ด eksctl create cluster ์‹คํ–‰ํ•˜๋ฉด default parameter๋กœ ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ๋ฐฐํฌ๋œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ yaml ํŒŒ์ผ๋กœ ์ž‘์„ฑํ•œ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ์ž‘์„ฑํ•˜์—ฌ ๋ฐฐํฌํ•˜๋ฉด ๊ตฌ์„ฑํŒŒ์ผ์— ๋ช…์‹œํ•œ ์˜ค๋ธŒ์ ํŠธ๋“ค์˜ ๋ฐ”๋ผ๋Š” ์ƒํƒœ(desired state)๋ฅผ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์ด์ ์ด ์žˆ๋‹ค.

1. Cluster ๊ตฌ์„ฑํŒŒ์ผ ์ž‘์„ฑ

~/environment/eks-demo-cluster.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: eks-demo # ์ƒ์„ฑํ•  EKS ํด๋Ÿฌ์Šคํ„ฐ๋ช…
  region: ap-northeast-2 # ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ƒ์„ฑํ•  ๋ฆฌ์ „
  version: "1.21"

vpc:
  cidr: "192.168.0.0/16" # ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์‚ฌ์šฉํ•  VPC์˜ CIDR

managedNodeGroups:
  - name: node-group # ํด๋Ÿฌ์Šคํ„ฐ์˜ ๋…ธ๋“œ ๊ทธ๋ฃน๋ช…
    instanceType: m5.large # ํด๋Ÿฌ์Šคํ„ฐ ์›Œ์ปค ๋…ธ๋“œ์˜ ์ธ์Šคํ„ด์Šค ํƒ€์ž…
    desiredCapacity: 3 # ํด๋Ÿฌ์Šคํ„ฐ ์›Œ์ปค ๋…ธ๋“œ์˜ ๊ฐฏ์ˆ˜
    volumeSize: 10  # ํด๋Ÿฌ์Šคํ„ฐ ์›Œ์ปค ๋…ธ๋“œ์˜ EBS ์šฉ๋Ÿ‰ (๋‹จ์œ„: GiB)
    iam:
      withAddonPolicies:
        imageBuilder: true # Amazon ECR์— ๋Œ€ํ•œ ๊ถŒํ•œ ์ถ”๊ฐ€
        # albIngress: true  # albIngress์— ๋Œ€ํ•œ ๊ถŒํ•œ ์ถ”๊ฐ€
        cloudWatch: true # cloudWatch์— ๋Œ€ํ•œ ๊ถŒํ•œ ์ถ”๊ฐ€
        autoScaler: true # auto scaling์— ๋Œ€ํ•œ ๊ถŒํ•œ ์ถ”๊ฐ€

cloudWatch:
  clusterLogging:
    enableTypes: ["*"]

2. ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋ฐฐํฌํ•œ๋‹ค.

1
eksctl create cluster -f eks-demo-cluster.yaml

ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์™„์ „ํžˆ ๋ฐฐํฌ๋˜๋Š”๋ฐ๊นŒ์ง€๋Š” ์•ฝ 15~20๋ถ„์ด ์†Œ์š”๋œ๋‹ค. AWS CloudFormation ์ฝ˜์†”์ฐฝ์—์„œ๋„ ์ง„ํ–‰์‚ฌํ•ญ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ƒ์„ฑํ•œ ํด๋Ÿฌ์Šคํ„ฐ ์ •๋ณด ํ™•์ธ

1
2
3
4
5
6
$ AWS_PROFILE=riley-admin eksctl get clusters 

2022-05-07 22:52:40 [โ„น]  eksctl version 0.95.0
2022-05-07 22:52:40 [โ„น]  using region ap-northeast-2
NAME		REGION		EKSCTL CREATED
eks-demo	ap-northeast-2	True

3. kubectl ์ธ์ฆ ์ •๋ณด ์„ค์ •

์ปจํ…์ŠคํŠธ ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅํ•˜๊ธฐ

1
2
3
4
$ kubectl config get-contexts

CURRENT   NAME               CLUSTER                                                         AUTHINFO                                                        NAMESPACE
*         eks-demo-cluster   eks-demo.ap-northeast-2.eksctl.io                               Administrator@eks-demo.ap-northeast-2.eksctl.io                 

kubectl ์ธ์ฆ์ •๋ณด alias ์ง€์ •

1
2
3
$ kubectx eks-demo-cluster=Administrator@eks-demo.ap-northeast-2.eksctl.io

Context "Administrator@eks-demo.ap-northeast-2.eksctl.io" renamed to "eks-demo-cluster".

์ปจํ…์ŠคํŠธ ์Šค์œ„์นญ

1
2
3
4
5
# switch context
kubectl config use-context eks-demo-cluster

# kubectx๋กœ switch context
kubectx eks-demo-cluster

๋ฐฐํฌ๋œ ๋…ธ๋“œ ํ™•์ธ

1
2
3
4
5
6
7
8
$ kubectx eks-demo-cluster
Switched to context "eks-demo-cluster".

$ kubectl get nodes 
NAME                                                STATUS   ROLES    AGE   VERSION
ip-192-168-22-34.ap-northeast-2.compute.internal    Ready    <none>   29m   v1.21.5-eks-9017834
ip-192-168-58-247.ap-northeast-2.compute.internal   Ready    <none>   29m   v1.21.5-eks-9017834
ip-192-168-81-71.ap-northeast-2.compute.internal    Ready    <none>   29m   v1.21.5-eks-9017834