본문 바로가기

AWS EKS 실습/EKS Beginner

Sample Application 배포

 

Sample Deployment YAML [deployment.yaml]

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ecsdemo-nodejs
  labels:
    app: ecsdemo-nodejs
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ecsdemo-nodejs
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: ecsdemo-nodejs
    spec:
      containers:
      - image: brentley/ecsdemo-nodejs:latest
        imagePullPolicy: Always
        name: ecsdemo-nodejs
        ports:
        - containerPort: 3000
          protocol: TCP

Sample Service YAML [service.yaml]

apiVersion: v1
kind: Service
metadata:
  name: ecsdemo-nodejs
spec:
  selector:
    app: ecsdemo-nodejs
  ports:
   -  protocol: TCP
      port: 80
      targetPort: 3000

 

$ kubectl apply -f deployment.yaml

 

$ kubect get deployment ecsdemo-nodejs

$ kubectl get service ecsdemo-nodejs

 

Frontend Service를 위한 service.yaml

apiVersion: v1
kind: Service
metadata:
  name: ecsdemo-frontend
spec:
  selector:
    app: ecsdemo-frontend
  type: LoadBalancer
  ports:
   -  protocol: TCP
      port: 80
      targetPort: 3000

Backend Service를 위한 service.yaml

apiVersion: v1
kind: Service
metadata:
  name: ecsdemo-nodejs
spec:
  selector:
    app: ecsdemo-nodejs
  ports:
   -  protocol: TCP
      port: 80
      targetPort: 3000

Service에서 어떤 type이 정해져 있지 않으면 Default Type으로 Cluster IP가 정의 된다. 이 값은 오직 Cluster 내부에서만 통신할 때 사용된다.

 

AWS에서 ELB에 대한 권한이 있는지 확인하기 위해서는 다음과 같이 role 여부를 확인한다.

aws iam get-role --role-name "AWSServiceRoleForElasticLoadBalancing" || aws iam create-service-linked-role --aws-service-name "elasticloadbalancing.amazonaws.com"
{
    "Role": {
        "Description": "Allows ELB to call AWS services on your behalf.", 
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17", 
            "Statement": [
                {
                    "Action": "sts:AssumeRole", 
                    "Effect": "Allow", 
                    "Principal": {
                        "Service": "elasticloadbalancing.amazonaws.com"
                    }
                }
            ]
        }, 
        "MaxSessionDuration": 3600, 
        "RoleId": "AROATHIILAC3HGN6AVHA5", 
        "CreateDate": "2020-07-10T02:50:16Z", 
        "RoleName": "AWSServiceRoleForElasticLoadBalancing", 
        "Path": "/aws-service-role/elasticloadbalancing.amazonaws.com/", 
        "RoleLastUsed": {
            "Region": "ap-northeast-2", 
            "LastUsedDate": "2020-12-09T23:42:58Z"
        }, 
        "Arn": "arn:aws:iam::221745184950:role/aws-service-role/elasticloadbalancing.amazonaws.com/AWSServiceRoleForElasticLoadBalancing"
    }
}

 

ㅇ 배포된 서비스 확인

 

$ kubectl get service ecsdemo-frontend

 

$ kubectl get service ecsdemo-frontend -o

 

ㅇ 서비스에 대한 scale up

 

$ kubectl scale deployment ecsdemo-nodejs --replicas=3

$ kubectl scale deployment ecsdemo-crystal --replicas=3