brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jun 18. 2021

EKS 1탄-3. 클러스터 만들기

실습 1탄 = 3/7

<1>  CLI로 EKS 클러스터 만들기 (선택)

<2>  Web Console로 EKS 클러스터 만들기  (선택)

<3> 자원 삭제 = Autoscaling Group을 반드시 삭제

<4>  AWS 배포법

<5> 다음 = 실습4. EKS, Container Insight

<10>   AWS EKS 실습 1탄




<1>  CLI로 EKS 클러스터 만들기 (선택)


AWS에서 EKS 클러스터 만들어 보자~

AWS EKS에서 Master는 AWS에서 관리한다.

우리는 WorkNode만 관리할 뿐이다.




1

디렉토리 이동

cd ~/environment

$ /home/ec2-user/environment 경로임


2

리전 변경 필요시

export AWS_REGION=ap-northeast-2

export AWS_REGION=us-east-1

export AWS_REGION=us-east-2

export AWS_REGION=us-west-1

export AWS_REGION=us-west-2


ap-northeast-2  = 서울

US East (N. Virginia) us-east-1

US East (Ohio) us-east-2

US West (N. California) us-west-1

US West (Oregon) us-west-2


echo ${AWS_REGION}


임의 IP블럭으로 만드는 예제이다.

// VPC 192.168.0.0/16

Subnet이 /19로 2개 또는 3개로 만들어진다.



cat << EOF > eks-demo-cluster.yaml

---

apiVersion: eksctl.io/v1alpha5

kind: ClusterConfig


metadata:

  name: eks-demo # 생성할 EKS 클러스터명

  region: ${AWS_REGION} # 클러스터를 생성할 리젼

  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 # AWS ECR에 대한 권한 추가

        albIngress: true  # albIngress에 대한 권한 추가

        cloudWatch: true # cloudWatch에 대한 권한 추가

        autoScaler: true # auto scaling에 대한 권한 추가


cloudWatch:

  clusterLogging:

    enableTypes: ["*"]

EOF



3

AWS EKS는 비용이 발생 된다.

테스트후 반드시 삭제하도록 하자.



4

아니면,  로컬 PC에  쿠버네티스 설치해 테스트 하자~

https://brunch.co.kr/@topasvga/1682



5

Amazon EKS 설치


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


(30분 소요 됨)

021-06-18 00:08:38 [✔]  EKS cluster "eks-demo" in "us-west-1" region is ready



// 생성실패도 다시 생성해야 할때 ?  

// vi eks-demo-cluster.yaml  해서 Cluster name을  eks-demo1으로 수정하면 계속 만들수 있음.


https://vclock.kr/timer/#countdown=00:10:00&enabled=0&seconds=0&sound=xylophone&loop=1


5

실패시 다른 리전에 설치법 ?


리전 수동으로 변경하도록 하자.

vi eks-demo-cluster.yaml

AWS_REGION=us-east-2



6

eks-demo 클러스터가 있는경우 수정하자.

eks-demo -> eks-demo1 으로 변경


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



vi eks-demo-cluster.yaml 

  version: "1.21"  을     version: "1.27"  로 변경


// 1.21은 더  이상 지원하지 않음.




[root@ip-172-31-40-122 ~]# more eks-demo-cluster.yaml 

---

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 # AWS ECR에 대한 권한 추가

        albIngress: true  # albIngress에 대한 권한 추가

        cloudWatch: true # cloudWatch에 대한 권한 추가

        autoScaler: true # auto scaling에 대한 권한 추가

cloudWatch:

  clusterLogging:

    enableTypes: ["*"]



127버전으로 변경


(30분 소요)




7

클러스터 완료후 확인

kubectl get nodes



8

확인

AWS console에서 EC2 확인



9

트라블 슈팅

us-east-1으로 할경우 아래와 같이 에러가 나온다.

"targeted availability zone, does not currently have sufficient capacity to support the cluster. Retry and choose from these availability zones: us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1f (Service: AmazonEKS; Status Code: 400"


=> cloud9 disk 용량을 늘려야 한다.

wget https://gist.githubusercontent.com/joozero/b48ee68e2174a4f1ead93aaf2b582090/raw/2dda79390a10328df66e5f6162846017c682bef5/resize.sh


sh resize.sh




10

kubectl describe configmap -n kube-system aws-auth


[root@ip-172-31-16-102 ~]# kubectl describe configmap -n kube-system aws-auth

Name:         aws-auth

Namespace:    kube-system

Labels:       <none>

Annotations:  <none>


Data

====

mapRoles:

----

- groups:

  - system:bootstrappers

  - system:nodes

  rolearn: arn:aws:iam::79xxxxxxxxx:role/eksctl-eks-demo1-nodegroup-node-g-NodeInstanceRole-OPMZXZF5T841

  username: system:node:{{EC2PrivateDNSName}}


Events:  <none>

[root@ip-172-31-16-102 ~]# 







<2>  Web Console로 EKS 클러스터 만들기  (선택)


AWS는 5개 버전을 지원한다.

시간이 지나면 변경된다.


1

EKS

왼편 Amazon EKS > Clusters


1.28

1.27

1.26

1.25

1.24

1.23 



2

role  필요





<3> 자원 삭제 = Autoscaling Group을 반드시 삭제


자원 삭제시 Autoscaling Group을 반드시 삭제하지.

오토 스케일링로 삭제하지 않고, EC2에서 서버 삭제하면 서버가 다시 생성되기 때문이다.


1

EC2도 없는지 확인 필수


2

EC2를 삭제 해도 Autoscaling 으로 다시 EC2가 생성되어 비용이 발생 할수도 있다.

반드시 EC2가 없는지 확인.







<4>  AWS 배포법


1

모니터링 하기

watch -d kubectl get deploy,svc,pods



2 배포하기


kubens  eks-sample-app 



kubectl create namespace eks-sample-app



cat <<EOT > eks-sample-deployment.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: eks-sample-linux-deployment

  namespace: eks-sample-app

  labels:

    app: eks-sample-linux-app

spec:

  replicas: 3

  selector:

    matchLabels:

      app: eks-sample-linux-app

  template:

    metadata:

      labels:

        app: eks-sample-linux-app

    spec:

      affinity:

        nodeAffinity:

          requiredDuringSchedulingIgnoredDuringExecution:

            nodeSelectorTerms:

            - matchExpressions:

              - key: kubernetes.io/arch

                operator: In

                values:

                - amd64

                - arm64

      containers:

      - name: nginx

        image: public.ecr.aws/nginx/nginx:1.23

        ports:

        - name: http

          containerPort: 80

        imagePullPolicy: IfNotPresent

      nodeSelector:

        kubernetes.io/os: linux

EOT


kubectl apply -f eks-sample-deployment.yaml





cat <<EOT > eks-sample-service.yaml

apiVersion: v1

kind: Service

metadata:

  name: eks-sample-linux-service

  namespace: eks-sample-app

  labels:

    app: eks-sample-linux-app

spec:

  selector:

    app: eks-sample-linux-app

  ports:

    - protocol: TCP

      port: 80

      targetPort: 80

EOT


kubectl apply -f eks-sample-service.yaml


kubectl get pods





https://aws.amazon.com/ko/getting-started/hands-on/deploy-kubernetes-app-amazon-eks/




<5> 다음 = 실습4. EKS, Container Insight


https://brunch.co.kr/@topasvga/1653




<10>    AWS EKS 실습 1탄


https://brunch.co.kr/@topasvga/1883


https://brunch.co.kr/@topasvga/1679


감사합니다.

매거진의 이전글 EKS 1탄-2. 도커 이미지,ECR

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari