Slide 1

Slide 1 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. 유병우 Buzzvil Kubernetes in Action on AWS

Slide 2

Slide 2 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Container orchestration tool? Why Kubernetes? Why Kops? Demo

Slide 3

Slide 3 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Container orchestration tool?

Slide 4

Slide 4 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Container? • State? • Relation? • History?

Slide 5

Slide 5 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Container? - Relation 격리된 공간 가상화 Overhead

Slide 6

Slide 6 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Container? - History # Use an official Python runtime as a parent image FROM python:2.7-slim # Set the working directory to /app WORKDIR /app # Copy the current directory contents into the container at /app ADD . /app # Install any needed packages specified in requirements.txt RUN pip install --trusted-host pypi.python.org -r requirements.txt # Make port 80 available to the world outside this container EXPOSE 80

Slide 7

Slide 7 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Container orchestration tool? EC2 Django EC2 Django EC2 Django EC2 Go EC2 Go EC2 Go 2 Apps + 2 AS Groups + 1 ALB Docker 도입 Django Go Application load balancer Nginx 3 Apps + 1 AS Groups Container orchestration tool 을 통해 이걸 해결해보자!

Slide 8

Slide 8 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Kubernetes?

Slide 9

Slide 9 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. 용어정리

Slide 10

Slide 10 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Cluster Cluster / Node / Pod

Slide 11

Slide 11 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. RC / Deployment / Service • ReplicationController (ReplicaSet) • 하나의 Pod 상태를 공유하는 Set • Deployment? • 업데이트! (RC 가 추가됨) • 어떻게 배포할지 설정 가능 How to expose them? Service

Slide 12

Slide 12 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Kubernetes? • Automatic binpacking • Horizontal scaling • Automated rollouts and rollbacks • Self-healing • Service discovery and load balancing

Slide 13

Slide 13 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automatic binpacking

Slide 14

Slide 14 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automatic binpacking Node 1 (4 CPU / 8G) 2 CPU / 2G Node 2 (4 CPU / 8G) 2 CPU / 2G 2 CPU / 2G 1 CPU / 2G

Slide 15

Slide 15 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automatic binpacking Node 1 (4 CPU / 8G) 2 CPU / 2G Node 2 (4 CPU / 8G) 2 CPU / 2G 2 CPU / 2G 1 CPU / 2G

Slide 16

Slide 16 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automatic binpacking Node 1 (4 CPU / 8G) 2 CPU / 2G 1 CPU / 2G Node 2 (4 CPU / 8G) 2 CPU / 2G 2 CPU / 2G 1 CPU / 2G

Slide 17

Slide 17 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automatic binpacking Node 1 (4 CPU / 8G) 2 CPU / 2G Node 2 (4 CPU / 8G) 2 CPU / 2G 2 CPU / 2G 1 CPU / 2G 1 CPU / 2G

Slide 18

Slide 18 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automatic binpacking 2 CPU / 16G 2 CPU / 4G 4 CPU / 8G 2 CPU / 2G 1 CPU / 2G 2 CPU / 16G 1 CPU / 4G 1 CPU / 8G 4 CPU / 8G 2 CPU / 2G 1 CPU / 2G 2 CPU / 16G 1 CPU / 4G 1 CPU / 8G 4 CPU / 8G 2 CPU / 2G 1 CPU / 2G 2 CPU / 16G 1 CPU / 6G 1 CPU / 2G 4 CPU / 8G 2 CPU / 2G 1 CPU / 2G 3 CPU / 4G 1 CPU / 8G

Slide 19

Slide 19 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Horizontal scaling

Slide 20

Slide 20 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Horizontal scaling

Slide 21

Slide 21 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automated rollouts and rollbacks

Slide 22

Slide 22 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automated rollouts and rollbacks https://kubernetes.io/docs/tutorials/kubernetes-basics/update-intro/

Slide 23

Slide 23 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Automated rollouts and rollbacks

Slide 24

Slide 24 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Self-healing

Slide 25

Slide 25 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Self-healing Node 1 App 1 App 2 Node 2 App 2 Node 3 App 3 Master Contoller Scheduler

Slide 26

Slide 26 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Self-healing Node 1 App 1 App 2 Node 2 App 2 Node 3 App 3’ Master Contoller Scheduler

Slide 27

Slide 27 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Self-healing Node 1 App 1 App 2 Node 2 App 2 Node 3 App 3 Master Contoller Scheduler

Slide 28

Slide 28 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Self-healing Node 1 App 1 App 2 Node 2 App 2 App 3 Master Contoller Scheduler

Slide 29

Slide 29 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Service discovery and load balancing

Slide 30

Slide 30 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Service discovery and load balancing {{service-name}}.{{namespace}}.svc.cluster.local

Slide 31

Slide 31 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Service discovery and load balancing • Internal • ClusterIP • External • LoadBalancer • NodePort

Slide 32

Slide 32 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why Kops?

Slide 33

Slide 33 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why kops? • AWS 위에 Kubernetes clusters 관리를 자동화 AWS AWS Kube

Slide 34

Slide 34 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Kube + α Why kops? • AWS 위에 Kubernetes clusters 관리를 자동화 S3 IAM VPC EC2 Route53

Slide 35

Slide 35 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why kops? • AWS 위에 Kubernetes clusters 관리를 자동화 • 고가용성(Highly Available) Kubernetes Masters

Slide 36

Slide 36 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Why kops? • AWS 위에 Kubernetes clusters 관리를 자동화 • 고가용성(Highly Available) Kubernetes Masters • State-sync model (dry-runs & Idempotency) • kops create cluster --zones us-west-2a ${NAME} • kops update cluster ${NAME} --yes

Slide 37

Slide 37 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Demo

Slide 38

Slide 38 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Prerequisites • Install CLI tools – kops / kubectl • IAM permissions

Slide 39

Slide 39 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Demo • Cluster 구성 (1 master & 2 nodes) • Web app & Nginx proxy 구성 • External load balancer 구성 • Auto scaling 설정

Slide 40

Slide 40 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. VPC Overview Cluster Load balancer hello-go Pod Pod Pod Pod autoscaler Nginx Pod Cluster autoscaler

Slide 41

Slide 41 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. VPC Cluster 구성 Cluster Master Node Node

Slide 42

Slide 42 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Cluster 구성 • 환경변수 설정 • export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id) • export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key) • export S3_BUCKET_NAME=k8s-state-test-honeyscreen-com • export KOPS_STATE_STORE=s3://${S3_BUCKET_NAME} • export CLUSTER_NAME=k8s-test.honeyscreen.com • export SSH_PUBLIC_KEY=~/.ssh/id_rsa.pub • export VPC={{VPC-ID}} • export CLUZTER_REGION=ap-northeast-2 • export CLUSTER_ZONE=${CLUZTER_REGION}a

Slide 43

Slide 43 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Cluster 구성 • S3 Bucket 만들기 / Cluster 생성

Slide 44

Slide 44 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Cluster 구성 • Cluster 확인 및 수정

Slide 45

Slide 45 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Cluster 구성 • Cluster 적용 • kops update cluster --name $CLUSTER_NAME –yes • Cluster 업데이트 • kops edit instancegroup nodes • kops update cluster --name $CLUSTER_NAME –yes

Slide 46

Slide 46 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Cluster 구성 • Dashboard 설치 • kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes- dashboard/v1.8.1.yaml • http://api.k8s-test.honeyscreen.com/ui

Slide 47

Slide 47 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. VPC Web app & Nginx proxy 구성 Cluster hello-go Pod Pod Pod Nginx Pod

Slide 48

Slide 48 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Web app & Nginx proxy 구성 • Web app - hello-go • Source code • Return Git revision • Build • kube/app-hello-go.yaml • kube/svc-hello-go.yaml • Nginx proxy • kube/app-nginx.yaml • kube/svc-nginx.yaml

Slide 49

Slide 49 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Web app - hello-go • main.go

Slide 50

Slide 50 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Web app – build-docker.sh • hello

Slide 51

Slide 51 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Web app – kube/app-hello-go.yaml

Slide 52

Slide 52 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Web app – kube/svc-hello-go.yaml

Slide 53

Slide 53 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Web app – kube/app-nginx.yaml

Slide 54

Slide 54 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. VPC External load balancer 구성 Cluster Load balancer hello-go Pod Pod Pod Nginx Pod

Slide 55

Slide 55 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Web app – kube/svc-nginx.yaml

Slide 56

Slide 56 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. External load balancer 구성 • Expose Nginx to Load balancer • kube/svc-nginx.yaml • Load balancer 확인 • Route53 에서 sub domain 할당

Slide 57

Slide 57 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. deploy.sh

Slide 58

Slide 58 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. VPC Auto scaling 설정 Cluster Load balancer hello-go Pod Pod Pod Pod autoscaler Nginx Pod Cluster autoscaler

Slide 59

Slide 59 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Auto scaling - Pod • kube/hpa-hello-go.yaml

Slide 60

Slide 60 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Auto scaling - Cluster • kube/app-autoscaler.yaml

Slide 61

Slide 61 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Increase load

Slide 62

Slide 62 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Increase load

Slide 63

Slide 63 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Decrease load

Slide 64

Slide 64 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Decrease load

Slide 65

Slide 65 text

© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. References • Github https://github.com/urunimi/kube-sample/ • E-mail [email protected] [email protected] We are hiring!

Slide 66

Slide 66 text

Q&A