AWS CLI๋ฅผ ํ†ตํ•ด EKS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šฐ๊ณ , AWS Access Key๋ฅผ ์ด์šฉํ•ด ์ ‘์†ํ•ด๋ณด์ž! ์ฒ˜์Œ์—๋Š” โ€˜EKS Cluster? ๊ทธ๊ฑฐ ๊ทธ๋ƒฅ ๋„์šฐ๋ฉด K8s ํด๋Ÿฌ์Šคํ„ฐ ๋„์šฐ๋Š” ๊ฑฐ ์•„๋‹Œ๊ฐ€?โ€™๋ผ๊ณ  ๋งŒ๋งŒํ•˜๊ฒŒ ๋ดค๋Š”๋ฐ, ์ด๋Ÿฐโ€ฆ EKS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šฐ๊ณ  ์‹ค์ œ ์ ‘์†๊นŒ์ง€ ํ•˜๋Š” ๊ณผ์ •์ด ์ˆœํƒ„์น˜ ์•Š์•˜๋‹ค. ์ด๋ฒˆ์— ์˜ˆํ–‰ ์—ฐ์Šต์œผ๋กœ ๊ฒฝํ—˜ํ•ด๋ดค์œผ๋‹ˆ ์ด์   ์ž์‹ ์žˆ๋‹ค!!

6 minute read

AWS CLI๋ฅผ ํ†ตํ•ด EKS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šฐ๊ณ , AWS Access Key๋ฅผ ์ด์šฉํ•ด ์ ‘์†ํ•ด๋ณด์ž! ์ฒ˜์Œ์—๋Š” โ€˜EKS Cluster? ๊ทธ๊ฑฐ ๊ทธ๋ƒฅ ๋„์šฐ๋ฉด K8s ํด๋Ÿฌ์Šคํ„ฐ ๋„์šฐ๋Š” ๊ฑฐ ์•„๋‹Œ๊ฐ€?โ€™๋ผ๊ณ  ๋งŒ๋งŒํ•˜๊ฒŒ ๋ดค๋Š”๋ฐ, ์ด๋Ÿฐโ€ฆ EKS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šฐ๊ณ  ์‹ค์ œ ์ ‘์†๊นŒ์ง€ ํ•˜๋Š” ๊ณผ์ •์ด ์ˆœํƒ„์น˜ ์•Š์•˜๋‹ค. ์ด๋ฒˆ์— ์˜ˆํ–‰ ์—ฐ์Šต์œผ๋กœ ๊ฒฝํ—˜ํ•ด๋ดค์œผ๋‹ˆ ์ด์   ์ž์‹ ์žˆ๋‹ค!!


EKS์˜ K8s ํด๋Ÿฌ์Šคํ„ฐ๋Š” ํฐ ๊ด€์ ์œผ๋กœ (1) ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํด๋Ÿฌ์Šคํ„ฐ์™€ (2) ์›Œ์ปค ๋…ธ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋…ธ๋“œ ๊ทธ๋ฃน์œผ๋กœ ์ด๋ค„์ง„๋‹ค.

(์„ ํƒ) Bastion ํ˜ธ์ŠคํŠธ ์„ธํŒ…ํ•˜๊ธฐ

๋งŒ์•ฝ AWS CLI๋ฅผ ๋ณธ์ธ ๋กœ์ปฌ์—์„œ ์ˆ˜ํ–‰ํ•œ๋‹ค๋ฉด, ์ƒ๊ด€ ์—†๋Š” ๋ถ€๋ถ„์ด๋‹ค. ๋ณธ์ธ์€ Bastion ํ˜ธ์ŠคํŠธ๋ฅผ ํ•˜๋‚˜ ๋„์›Œ์„œ ํ•ด๋‹น ํ˜ธ์ŠคํŠธ์—์„œ AWS CLI๋กœ ์ž‘์—… ํ–ˆ๋‹ค. ์ด ๊ฒฝ์šฐ ์•„๋ž˜ ๋ช…๋ น์–ด๋“ค๋กœ ํŒจํ‚ค์ง€๋“ค์„ ์„ค์น˜ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค.

# ๊ธฐ๋ณธ ํŒจํ‚ค์ง€ ์„ค์น˜
sudo apt update && \
  sudo apt install -y jq \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    gettext \
    software-properties-common


# aws-cli ์„ค์น˜
sudo apt-get install awscli
aws --version

# kubectl ์„ค์น˜
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \
    echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list && \
    sudo apt update && \
    sudo apt install -y kubectl=1.25.0-00
kubectl version

AWS CLI ์„ธํŒ…ํ•˜๊ธฐ

EKS ํด๋Ÿฌ์Šคํ„ฐ๋Š” ์ฝ˜์†”์ด ์•„๋‹Œ AWS CLI๋ฅผ ์‚ฌ์šฉํ•ด ๋„์šธ ๊ฒƒ์ด๋‹ค. EKS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šฐ๋Š” ๊ถŒํ•œ์ด ์žˆ๋Š” IAM ์œ ์ €๋กœ AWS CLI๋ฅผ ์„ธํŒ…ํ•˜์ž. ์ด ๋‹จ๊ณ„์—์„œ๋Š” ์ผ๋‹จ Administrator Role์„ ๋ถ€์—ฌํ•˜๋Š”๊ฒŒ ํŽธํ–ˆ๋‹ค.

์ค‘์š”ํ•œ ์ ์€ EKS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šฐ๋ฉด, ์ฒ˜์Œ์—๋Š” ํ•ด๋‹น ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šด IAM ์œ ์ €๋ฅผ ์ œ์™ธํ•˜๊ณ ๋Š” ํ•ด๋‹น EKS ํด๋Ÿฌ์Šคํ„ฐ์— ์ ‘์†ํ•  ์ˆ˜ ์—†๋‹ค๋Š” ์ ์ด๋‹ค!! ๊ทธ๋ž˜์„œ AWS CLI ์„ธํŒ…์„ ์–ด๋–ค IAM ์œ ์ €๋กœ ํ•˜๋Š”์ง€๊ฐ€ ์ •๋ง ์ค‘์š”ํ•˜๋‹ค!!!

EKS ํด๋Ÿฌ์Šคํ„ฐ ๋„์šฐ๊ธฐ

๋จผ์ € ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” EKS ํด๋Ÿฌ์Šคํ„ฐ๋ถ€ํ„ฐ ๋„์›Œ๋ณด์ž.

๋จผ์ € EKS ํด๋Ÿฌ์Šคํ„ฐ์— ๋ถ€์—ฌํ•  IAM Role์„ ์„ธํŒ…ํ•˜์ž. ์ด๋ฆ„์€ xxxx-eks-cluster-role ์ •๋„๋กœ ์„ค์ •ํ•˜๊ณ  ์•„๋ž˜์˜ ๋‘ IAM Policy๋ฅผ ๋ถ™์—ฌ์ฃผ์ž.

  • AmazonEKSClusterPolicy
  • AmazonEKSVPCResourceController

๊ทธ ์ดํ›„์—” bastion ํ˜ธ์ŠคํŠธ์—์„œ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹ค.

aws eks create-cluster \
	--region us-west-2 \
	--name xxxx-eks-cluster \
	--kubernetes-version 1.25 \
	--role-arn arn:aws:iam::12345678:role/xxxx-eks-cluster-role \
        --resources-vpc-config subnetIds=subnet-xxxx,subnet-xxxx,subnet-xxxx,subnet-xxxx

EKS ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์ž˜ ๋„์›Œ์กŒ์œผ๋ฉด kubectl๋กœ ์ ‘์†ํ•ด๋ณด์ž! ์ ‘์†์— ์‚ฌ์šฉํ•  kubeconfig๋ฅผ ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ์ƒ์„ฑํ•œ๋‹ค.

aws eks update-kubeconfig
	--region us-west-2
	--name xxxx-eks-cluster
	--kubeconfig ./xxxx-eks-config

๋งŒ๋“ค์–ด๋‘” xxxx-eks-config๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ ‘์†์„ ํ…Œ์ŠคํŠธ ํ•œ๋‹ค.

$ kubectl get service
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.111.0.1   <none>        443/TCP   2d19h

EKS ๋…ธ๋“œ๊ทธ๋ฃน ๋„์šฐ๊ธฐ

๋‹ค์Œ์€ ์›Œ์ปค ๋…ธ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” EKS ๋…ธ๋“œ๊ทธ๋ฃน์„ ๋„์šฐ์ž!

์ฐธ๊ณ ๋กœ ๋…ธ๋“œ๊ทธ๋ฃน๊นŒ์ง€ ๋„์›Œ์•ผ ๋‹ค๋ฅธ AWS IAM User์—๊ฒŒ EKS ํด๋Ÿฌ์Šคํ„ฐ ์ ‘์†ํ•  ๊ถŒํ•œ์„ ๋ถ€์—ฌ ํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค!

์ด EKS ๋…ธ๋“œ๊ทธ๋ฃน์—๋„ IAM Role์„ ๋ถ€์—ฌํ•ด์•ผ ํ•œ๋‹ค. xxxx-eks-nodegroup-role ์ •๋„๋กœ ์„ค์ •ํ•˜๊ณ  ์•„๋ž˜์˜ IAM Policy๋ฅผ ๋ถ™์—ฌ์ฃผ์ž.

  • AmazonEKSWorkerNodePolicy
  • AmazonEC2ContainerRegistryReadOnly
  • AmazonEKS_CNI_Policy

๊ทธ ์ดํ›„์—” bastion ํ˜ธ์ŠคํŠธ์—์„œ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹ค.

aws eks create-nodegroup \
	--cluster-name xxxx-eks-cluster \
	--nodegroup-name xxxx-eks-nodegroup \
	--subnets subnet-xxxx subnet-xxxx \
	--node-role arn:aws:iam::12345678:role/xxxx-eks-nodegroup-role

EKS ํด๋Ÿฌ์Šคํ„ฐ ์ ‘์† ๊ถŒํ•œ ์„ค์ •

EKS ํด๋Ÿฌ์Šคํ„ฐ๋Š” K8s ํด๋Ÿฌ์Šคํ„ฐ์— ์ ‘์†ํ•˜๋Š” IAM User/Role์˜ ๊ถŒํ•œ์„ kube-system ๋„ค์ž„์ŠคํŽ˜์ด์Šค์— ์žˆ๋Š” configmap/aws-auth์—์„œ ๊ด€๋ฆฌํ•œ๋‹ค. ์š” ConfigMap์€ EKS ๋…ธ๋“œ๊ทธ๋ฃน์ด EKS ํด๋Ÿฌ์Šคํ„ฐ์— ๋ถ™์œผ๋ฉด ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜๋Š” ๋ฆฌ์†Œ์Šค๋‹ค!

kubectl get configmap aws-auth -n kube-system -o yaml๋กœ ๋‚ด์šฉ์„ ํ™•์ธํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

apiVersion: v1
kind: ConfigMap
metadata:
  name: aws-auth
  namespace: kube-system
data:
  mapRoles: |
    - groups:
      - system:bootstrappers
      - system:nodes
      rolearn: arn:aws:iam::12345678:role/xxxx-eks-nodegroup-role
      username: system:node:

์ฒ˜์Œ์—๋Š” nodegroup์„ ๋งŒ๋“ค๋•Œ ๋ถ€์—ฌํ•œ IAM Role๋งŒ ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค! ์ด์ œ ๋‹ค๋ฅธ IAM ์œ ์ €์™€ Role์„ ๋“ฑ๋กํ•ด๋ณด์ž!

data:
  mapRoles: |
    - groups: ...
    - groups:
      - system:masters
      rolearn: arn:aws:iam::12345678:role/Administrator
      username: adminRole
  mapUsers: |
    - groups:
      - system:masters
      userarn: arn:aws:iam::12345678:user/BlueHorn
      username: bluehorn

IAM ์œ ์ €๋ฅผ ๋“ฑ๋กํ•œ๋‹ค๋ฉด data.mapUsers.groups[*]์— ๋“ฑ๋กํ•˜๋ฉด ๋˜๊ณ , IAM Role์„ ๋“ฑ๋กํ•œ๋‹ค๋ฉด data.mapRoles.groups[*]์— ๋“ฑ๋กํ•œ๋‹ค.


ํ›„๊ธฐ

vs. EC2์— ์ง์ ‘ K8s ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์ถ•

CKA ์‹œํ—˜ ๋•Œ ์—ฐ์Šต ํ–ˆ๋˜, ๋…ธ๋“œ ๋จธ์‹ ์— kubeadm์œผ๋กœ ์ง์ ‘ ๋…ธ๋“œ ๋“ฑ๋กํ•ด์„œ K8s ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์ถ•ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” ํ›จ์”ฌ ์‰ฝ๋‹ค! aws eks ์ปค๋งจ๋“œ๋ฅผ 3๋ฒˆ๋งŒ ์ž…๋ ฅํ•ด์„œ K8s ํด๋Ÿฌ์Šคํ„ฐ ๋งŒ๋“ค์—ˆ์œผ๋‹ˆ ํ›จ์”ฌ ํŽธํ•œ์…ˆ.

vs. AWS ECS

์ด๊ฑด ์‚ฌ์‹ค AWS ECS๋ž‘ K8s๋ž‘ ๋น„๊ต๋„ ๊ฐ™์ด ๋“ค์–ด๊ฐˆ ์ˆ˜ ๋ฐ–์— ์—†๊ธด ํ•˜๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ AWS์—์„œ ์…‹์—…ํ•˜๋Š” ๊ฒƒ๋งŒ ๋น„๊ตํ•˜๋ฉด AWS EKS ์ชฝ์ด ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ตฌ์ถ•ํ•˜๊ณ  Deployment๋ฅผ ๋„์šฐ๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ํ›จ์”ฌ ๋น ๋ฅด๋‹ค! ์ด๋Ÿฌ๋‹ค๊ฐ€ ์˜์˜ AWS ECS๋Š” ์•ˆ ์“ฐ๊ฒŒ ๋˜๋ฒ„๋ฆฌ๋Š” ๊ฑธ๊นŒ? ใ… ใ…  ์•„์ง AWS ECS ๋„์šฐ๋Š” ๊ฑด ํฌ์ŠคํŠธ๋กœ ์ •๋ฆฌ๋ฅผ ๋ชป ํ–ˆ๋Š”๋ฐ ์–ผ๋ฅธ ์ •๋ฆฌํ•ด์•ผ ๊ฒ ๋‹ค.

์‚ฝ์งˆ์˜ ๊ธฐ๋กโ€ฆ

์‚ฌ์‹ค EKS ํด๋Ÿฌ์Šคํ„ฐ ๋„์šฐ๋Š” ๊ฑธ ํ•œ๋ฒˆ์— ์„ฑ๊ณตํ•œ ๊ฑด ์•„๋‹ˆ๋‹ค.

1. AWS ์ฝ˜์†”์—์„œ ๋„์šฐ๊ธฐ

EKS ํด๋Ÿฌ์Šคํ„ฐ ๋„์šฐ๋ฉด ์ฒ˜์Œ์—” ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋„์šด ์œ ์ €๋งŒ ์ ‘์† ๊ฐ€๋Šฅํ•˜๋‹จ ๊ฑธ ๋ชฐ๋ž์–ด์„œ, AWS ์œ ์ €์˜ Access Key ๋ฐ›๊ณ  ๋‹ค์‹œ ๋„์›Œ์•ผ ํ–ˆ๋‹ค ใ… ใ… 

2. eksctl๋กœ ๋„์šฐ๊ธฐ

์™œ ์ธ์ง€ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ EKS ๋…ธ๋“œ๊ทธ๋ฃน ๋„์šธ ๋•Œ CloudFormation ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์„œ ์‹คํŒจํ–ˆ๋‹ค;; ๊ฒฐ๊ตญ์—” ์ •ํ†ต ๋ฐฉ์‹์ธ AWS CLI๋กœ ๋„์› ๋‹ค!

๋‹ค์Œ์€ ๋ญ˜ ํ•ด๋ณผ๊นŒ?

  1. EKS ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ํ…Œ๋ผํผ์œผ๋กœ ๋„์šฐ๊ธฐ
  2. EKS ํด๋Ÿฌ์Šคํ„ฐ ์ ‘์† ๊ถŒํ•œ๋„ ํ…Œ๋ผํผ์œผ๋กœ ์„ค์ •ํ•ด๋ณด๊ธฐ