본문 바로가기
프로젝트

Application 배포 (By AWS EKS, Kubernetes)

by 엑츄얼리 2021. 8. 4.

1. EKS 구성

IAM user 생성

IAM 생성 및 권한 설정

* IAM 생성 이유

=> EKS는 보안상 Root User로 생성/접속하는 것을 권하지 않고

     EKS를 관리하기 위한 권한(Kubernetes RBAC authorization)을 EKS를 생성한 IAM으로 부터 할당

 

$ aws sts get-caller-identity

=> IAM 확인

    

C:\Users\82102\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\alswkdrb1

=> wsl 홈디렉터리 위치

 

eks-cluster-config.yml

---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: cloud-eks-cluster
  region: ap-northeast-2

availabilityZones: ["ap-northeast-2a", "ap-northeast-2c"]

iam:
  withOIDC: true

managedNodeGroups:
- name: cloud-eks-workers
  desiredCapacity: 1
  iam:
    withAddonPolicies:
      albIngress: true
  instanceTypes: ["c4.large","c5.large"]
  spot: true
#  instanceType: t3.small
#  ssh:
#    publicKeyName: "<your key pair name>"
#    https://ap-northeast-2.console.aws.amazon.com/ec2/v2/home?region=ap-northeast-2#KeyPairs:

cloudWatch:
    clusterLogging:
        enableTypes: ["audit", "authenticator", "controllerManager"]

$ eksctl create cluster -f ./eks-cluster-config.yml

=> cluster 생성

 

* CLI로 생성 방법

eksctl create cluster \
--name cloud-eks-01 \
--version 1.18 \
--region ap-northeast-2 \
--zones=ap-northeast-2a,ap-northeast-2c \
--nodegroup-name cloud-eks-workers \
--nodes 1 \
--nodes-min 1 \
--nodes-max 3 \
--with-oidc \
--managed \
--alb-ingress-access \
--spot \
--instance-types=c4.large,c5.large

cluster가 생성되며 node가 추가됨

2. Application 배포

2-1) Database 배포(mariaDB)

 

mysql-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: alswkdrb1/box1:mariadb_v2
        name: mysql
        ports:
        - containerPort: 3306
          name: mysql

$ kubectl apply -f mysql-deployment.yaml

=> EKS에 DB 배포

 

$ kubectl describe deployment mysql

=> 배포된 DB 정보 확인 

배포 정보 확인

mysql-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None

$ kubectl apply -f mysql-service.yaml

$ kubectl get pods -l app=mysql

=> mysql 서비스 방식을 배포, Pod 정보 확인

Pod 정보 확인

 

2-2) Flask App 배포

 

flask-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloud-flask
  labels:
    app: cloud-flask
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cloud-flask
  strategy:
    rollingUpdate:
      maxSurge: 20%
      maxUnavailable: 20%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: cloud-flask
    spec:
      containers:
      - image: alswkdrb1/box1:cloudflask_v2
        imagePullPolicy: Always
        name: cloud-flask
        ports:
        - containerPort: 5000
          protocol: TCP
        env:
        - name: DB_USER
          value: root
        - name: DB_PASSWORD
          value: "189756"
        - name: DB_NAME
          value: alswkdrb
        - name: DB_HOST
          value: mysql

 

$ kubectl apply -f flask-deployment.yaml

$ kubectl describe deployment cloud-flask

=> Flask App 이미지 배포 및 배포 정보 확인

Flask image 배포 정보 확인

flask-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None

$ kubectl apply -f flask-service.yaml

$ kubectl get pods -l app=cloud-flask

=> Flask All의 서비스 방식 배포 및 Pod 정보 확인

Pods 정보 확인

$ kubectl get svc cloud-flask-svc

=> Service type을 외부로 노출 시켰으므로 LB Endpoint 확인 가능

LB endpoint 확인 가능

3. Application 접근 및 제어

LB endpoint 접근
DB 추가
user_id : 2 삭제

 

$ eksctl delete cluster --region=ap-northeast-2 --name=cloud-eks-cluster

=> eks 삭제

댓글