이미지 기반의 배포 패러다임 Immutable infrastructure

120
Immutable Infrastructure Daekwon Kim [email protected]

description

2014 Programer 세미나 데이 발표.

Transcript of 이미지 기반의 배포 패러다임 Immutable infrastructure

Page 1: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

Daekwon�Kim

[email protected]

Page 2: 이미지 기반의 배포 패러다임 Immutable infrastructure

nacyot

@nacyot

Ruby�programmer

http://nacyot.com

Page 3: 이미지 기반의 배포 패러다임 Immutable infrastructure

Web�Development

Ruby�on�Rails

Programming�Languages

Visualization

Translation

Deployment

Page 4: 이미지 기반의 배포 패러다임 Immutable infrastructure

Deployment

Immutable�Infrastructure

Page 5: 이미지 기반의 배포 패러다임 Immutable infrastructure

Leevi

http://leevi.co.kr/

Page 6: 이미지 기반의 배포 패러다임 Immutable infrastructure

Remotty

http://blog.remotty.com

Page 7: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 8: 이미지 기반의 배포 패러다임 Immutable infrastructure

지난�이야기

Web�Development

Server�Management

Amazon�Web�Service

Page 9: 이미지 기반의 배포 패러다임 Immutable infrastructure

오늘�이야기

Immutable�Infrastructure

Disposable�Components

Orchestration

Blue�Green�Deployment

Continuous�Delivery

Page 10: 이미지 기반의 배포 패러다임 Immutable infrastructure

새로운�툴

Chef�/�Puppet�/�Ansible

Docker

Vagrant

Packer

Serf

ServerSpec

Amazon�Web�Service

Page 11: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 12: 이미지 기반의 배포 패러다임 Immutable infrastructure

TOC

Cloud

Auto�Scaling

Image

Deploy

Immutable�Infrastructure

Disposable�Components

Configuration�Management

Docker

HashiCorp

Page 13: 이미지 기반의 배포 패러다임 Immutable infrastructure

Cloud

SaaS

PasS

IaaS

Page 14: 이미지 기반의 배포 패러다임 Immutable infrastructure

Cloud

Software�as�a�Service

Google�Apps

Adobe�Creative�Cloud

Platform�as�a�Service

Heroku

Google�App�Engine

Infrastructure�as�a�Service

Amazon�Web�Service

Ucloud�biz

Page 15: 이미지 기반의 배포 패러다임 Immutable infrastructure

Platform�as�a�Service

Page 16: 이미지 기반의 배포 패러다임 Immutable infrastructure

컴퓨터�vs�클라우드

Page 17: 이미지 기반의 배포 패러다임 Immutable infrastructure

컴퓨터(서버)

물리적�실체

공간적�제약

장소적�제약

예산적�제약

유지보수

Page 18: 이미지 기반의 배포 패러다임 Immutable infrastructure

클라우드�위의�컴퓨터

비물리적�실체

공간적�제약?

장소적�제약?

예산적�제약?

유지보수?

Page 19: 이미지 기반의 배포 패러다임 Immutable infrastructure

Delegate,�Delegate,�Delegate

Page 20: 이미지 기반의 배포 패러다임 Immutable infrastructure

공간적�제약

언제든�원하는�만큼�사용할�수�있음

물리적�서버를�설치할�필요�없음

Page 21: 이미지 기반의 배포 패러다임 Immutable infrastructure

장소적�제약

원하는�리젼(장소)에서�서비스�가능

AWS�EC2,�Digital�Ocean

원하는�위치에서�배포�가능

CDN,�AWS�CloudFront

Page 22: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 23: 이미지 기반의 배포 패러다임 Immutable infrastructure

예산적�제약

매몰비용이�거의�발생하지�않음

서버를�구입할�필요�없음

월�단위�대여할�필요�없음

사용한�만큼만�내면�됨

시간�단위�과금

Page 24: 이미지 기반의 배포 패러다임 Immutable infrastructure

유지보수

필요없음

Disposable�Components?

Page 25: 이미지 기반의 배포 패러다임 Immutable infrastructure

"Amazon�Web�Service는�인터넷의�발전소다."

타마카와�켄

Page 26: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 27: 이미지 기반의 배포 패러다임 Immutable infrastructure

디지털�오션�예제

Page 28: 이미지 기반의 배포 패러다임 Immutable infrastructure

서버�실행하기

$�tugboat�create�ContainerShip�-s�66�-i�2158507�-r�6�-k�301023$�tugboat�dropletsContainerShip�(ip:�128.199.253.99,�status:�new,�region:�6,�id:�1383635)

Page 29: 이미지 기반의 배포 패러다임 Immutable infrastructure

서버�종료하기

$�tugboat�destroy�ContainerShipDroplet�fuzzy�name�provided.�Finding�droplet�ID...done,�1383635�(ContainerShip)Warning!�Potentially�destructive�action.�Please�confirm�[y/n]:�yQueuing�destroy�for�1383635�(ContainerShip)...done

Page 30: 이미지 기반의 배포 패러다임 Immutable infrastructure

Billing

Page 31: 이미지 기반의 배포 패러다임 Immutable infrastructure

10원

Page 32: 이미지 기반의 배포 패러다임 Immutable infrastructure

Cloud�!=�Server�Hosting

Page 33: 이미지 기반의 배포 패러다임 Immutable infrastructure

RRRSpec

분산�테스트�프레임워크

Page 34: 이미지 기반의 배포 패러다임 Immutable infrastructure

RRRSpec

테스트�17000개

1대로�몇�시간�걸림

Page 35: 이미지 기반의 배포 패러다임 Immutable infrastructure

RRRSpec

1대�*�몇�시간

==

EC2�스팟�인스턴스�60대�*�8~9분

Page 36: 이미지 기반의 배포 패러다임 Immutable infrastructure

Deployment�on�Cloud

Page 37: 이미지 기반의 배포 패러다임 Immutable infrastructure

Auto�Scaling

부하가�커지면

자동적으로�인스턴스가�실행되고(Scale�Out)

부하가�작아지면

자동적으로�인스턴스가�종료됨

Page 38: 이미지 기반의 배포 패러다임 Immutable infrastructure

Auto�Scaling의�장점

유연한�대응

합리적�비용

Page 39: 이미지 기반의 배포 패러다임 Immutable infrastructure

Auto�Scaling의�조건

어플리케이션�설계

정교한�비지니스�로직�분리

서버�환경�설정�분리�및�자동화

데이터�스토어�분리

Page 40: 이미지 기반의 배포 패러다임 Immutable infrastructure

When�in�Rome,�do�as�the�Romans�do

클라우드�위에선�클라우드에�어울리는�설계가�필요

Best�Practice

CDP�클라우드�설계�원칙

The�Twelve-Factor�App

Page 41: 이미지 기반의 배포 패러다임 Immutable infrastructure

CDP�클라우드�설계�원칙

가능한�한�서비스를�이용

생각보다�행동으로

작은�규모로�시작하여�스케일�아웃

변화를�전�계층에서�처리

고장을�위한�설계

처음뿐이�아닌�주기적인�개선

Page 42: 이미지 기반의 배포 패러다임 Immutable infrastructure

Auto�Scaling을�전제로�한�컴퓨터란

어플리케이션이�가동되기�위한�환경이�구성된

인스턴스로부터�Stamp�패턴으로�생성된

AMI�이미지로부터�생성된

가상�인스턴스(컴퓨터)

Page 43: 이미지 기반의 배포 패러다임 Immutable infrastructure

Auto�Scaling을�전제로�한�컴퓨터란

어플리케이션이�가동되기�위한�환경이�구성된

인스턴스로부터�Stamp�패턴으로�생성된

AMI�이미지로부터�생성된

Disposable�Components

Page 44: 이미지 기반의 배포 패러다임 Immutable infrastructure

Disposable�Copmonent

쓰고

버리는

Page 45: 이미지 기반의 배포 패러다임 Immutable infrastructure

Disposable�Copmonent

미리�설정된

쓰고

버리는

인스턴스(컴퓨터)

Page 46: 이미지 기반의 배포 패러다임 Immutable infrastructure

Disposable�Copmonent

서버�설정?

서버�관리?

Page 47: 이미지 기반의 배포 패러다임 Immutable infrastructure

Image

Page 48: 이미지 기반의 배포 패러다임 Immutable infrastructure

Image

새로운�문제

Page 49: 이미지 기반의 배포 패러다임 Immutable infrastructure

Image

이미지는�정말로�작동�가능한가?

Page 50: 이미지 기반의 배포 패러다임 Immutable infrastructure

Image

아마도…

Page 51: 이미지 기반의 배포 패러다임 Immutable infrastructure

최초의�이미지는�어디서�오는가?

서버�설정

useradd�…

set�env

apt-get�update

apt-get�install�…(순서!!)

ufw�…

iptable�…

Page 52: 이미지 기반의 배포 패러다임 Immutable infrastructure

최초의�이미지는�어디서�오는가?

어플리케이션�설치

ruby�build

apt-get�…

gem�install�bundler

git�clone�…

bundle�inastll

configuration

run�application�server

server�proxy

Page 53: 이미지 기반의 배포 패러다임 Immutable infrastructure

어플리케이션이�업데이트�되면?

어플리케이션�업데이트

git�pull�…

apt-get�…

bundle�update

configuration

Page 54: 이미지 기반의 배포 패러다임 Immutable infrastructure

유지보수

Page 55: 이미지 기반의 배포 패러다임 Immutable infrastructure

The�system�becomes�a�house�of�cards.�You�fear�any�changeand�you�fear�replacing�it�since�you�don’t�know�everything

about�how�it�works.

Trash�Your�Servers�and�Burn�Your�Code:�Immutable�Infrastructure�andDisposable�Components,�Chad�Fowler

Page 56: 이미지 기반의 배포 패러다임 Immutable infrastructure

서버�관리의�본질은�전역적�환경설정

서버는

하드웨어부터

OS를�거쳐

어플리케이션까지

모든�요소들이�얽히고�섥혀있는�곳

의존성�거의�관리�불가능

Page 57: 이미지 기반의 배포 패러다임 Immutable infrastructure

Stateful�Image

그저�이미지화�했을�뿐이고

Page 58: 이미지 기반의 배포 패러다임 Immutable infrastructure

Stateful�Image

복원�불가능

검증�불가능

일단�돌아는�감

안전�불감증

Page 59: 이미지 기반의 배포 패러다임 Immutable infrastructure

Stateful�Image

Disposable�Components

from�Recycled�Image

Page 60: 이미지 기반의 배포 패러다임 Immutable infrastructure

State

프로그래머의�원죄

전역변수를�사용하지�말라

Page 61: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 62: 이미지 기반의 배포 패러다임 Immutable infrastructure

Configuration�Management

Page 63: 이미지 기반의 배포 패러다임 Immutable infrastructure

"상태�관리가�귀찮으면�관리�안하면�되잖아"

이토�나오야

Page 64: 이미지 기반의 배포 패러다임 Immutable infrastructure

Infrastructure�as�Code

이토�나오야

Page 65: 이미지 기반의 배포 패러다임 Immutable infrastructure

Configuration�Management

Chef

Puppet

Ansible

Page 66: 이미지 기반의 배포 패러다임 Immutable infrastructure

Configuration�Management

Idempotence(멱등)

Page 67: 이미지 기반의 배포 패러다임 Immutable infrastructure

Configuration�Management

복원�가능

Build

검증�가능

Serverspec

이력�관리

Infrastructure�as�Code

Page 68: 이미지 기반의 배포 패러다임 Immutable infrastructure

Build

#�Chef�Cookbook�::�MyServer#�Recipe::�Install�Apache

log�'Install�Apache'package�'httpd'�do��action�:installend

Page 69: 이미지 기반의 배포 패러다임 Immutable infrastructure

ServerSpec

require�'spec_helper'

describe�package('httpd')�do��it�{�should�be_installed�}end

describe�service('httpd')�do��it�{�should�be_enabled���}��it�{�should�be_running���}end

describe�port(80)�do��it�{�should�be_listening�}end

Page 70: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 71: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 72: 이미지 기반의 배포 패러다임 Immutable infrastructure

Configuration�Management

Deployment

Page 73: 이미지 기반의 배포 패러다임 Immutable infrastructure

Vagrant

Provisioner

Provider

Page 74: 이미지 기반의 배포 패러다임 Immutable infrastructure

Vagrant

Provisioner�=�Chef

Provider�=�Vmware

Page 75: 이미지 기반의 배포 패러다임 Immutable infrastructure

Vagrant

Provisioner�=�Chef

Provider�=�AWS�EC2

Page 76: 이미지 기반의 배포 패러다임 Immutable infrastructure

Vagrant

Provisioning�=�Chef

Provider�=�Digital�Ocean

Page 77: 이미지 기반의 배포 패러다임 Immutable infrastructure

Vagrant

HashiCorp의�야망

Page 78: 이미지 기반의 배포 패러다임 Immutable infrastructure

Vagrant

뒤에서�다시

Page 79: 이미지 기반의 배포 패러다임 Immutable infrastructure

Server�Image

Stateless

Configuration�Management

Page 80: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

Page 81: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable?

변경�불가능

in�Java

String�vs�StringBuffer

함수형�프로그래밍�언어

Page 82: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�==�Stateless

Page 83: 이미지 기반의 배포 패러다임 Immutable infrastructure

Travis�CI

커밋�할�때마다

새로운�빌드�환경�구축

Heroku

푸쉬�할�때마다

새로운�어플리케이션�이미지�생성

Page 84: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

관리가능하고

Configuration�Management

Page 85: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

테스트�가능한

ServerSpec

Page 86: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

Stateless하고

Build

Page 87: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

Scalable한

Stamp�Pattern

Page 88: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

이미지�기반의

Lightweight,�Portable

Page 89: 이미지 기반의 배포 패러다임 Immutable infrastructure

Immutable�Infrastructure

관리가능하고

테스트�가능하며

Stateless하고

Scalable한

이미지�기반의

어플리케이션�배포

Page 90: 이미지 기반의 배포 패러다임 Immutable infrastructure
Page 91: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker

"Docker�is�an�open-source�engine�that�automates�thedeployment�of�any�application�as�a�lightweight,�portable,�self-

sufficient�container�that�will�run�virtually�anywhere"

Page 92: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker

한마디로

Build�Once,�Run�Anywhere

Page 93: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker

Page 94: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker

Image

Container

Dockerfile

Page 95: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker�Image

Build

Page 96: 이미지 기반의 배포 패러다임 Immutable infrastructure

Dockerfile

FROM�ubuntu:12.04MAINTAINER�Daekwon�Kim�

#�Run�upgradeRUN�echo�"deb�http://archive.ubuntu.com/ubuntu�precise�main�universe"�>�/etc/apt/sources.listRUN�apt-get�update

#�Install�basic�packagesRUN�apt-get�-qq�-y�install�git�curl�build-essential

#�Install�apache2RUN�apt-get�-qq�-y�install�apache2ENV�APACHE_RUN_USER�www-dataENV�APACHE_RUN_GROUP�www-dataENV�APACHE_LOG_DIR�/var/log/apache2RUN�a2enmod�rewrite

<[email protected]>

Page 97: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker�Container

Run

Page 98: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker-registry

Image�Archive

Page 99: 이미지 기반의 배포 패러다임 Immutable infrastructure

예제)�Remotty�공동가계부�빌드/배포�구상도

Github�Hook

Jenkins

Local

Push�Image�to�Docker�Registry

Remote(Stage�Server)

Notify

Page 100: 이미지 기반의 배포 패러다임 Immutable infrastructure

Local(Build�Serve)

Docker�Build(test)

Docker�Build(application)

Push�Image�to�Docker�Registry

Page 101: 이미지 기반의 배포 패러다임 Immutable infrastructure

Dockerfile

FROM�nacyot-bbapiMAINTAINER�Daekwon�Kim�

ADD�.�/workspace

#�ENVENV�RAILS_ENV�test

#�BuildRUN�cd�/workspace;�echo�'gem:�--no-ri�--no-rdoc'�>�~/.gemrcRUN�cd�/workspace;�bundle�install�--without�developmentRUN�cd�/workspace;�bundle�exec�rake�db:migrate�RAILS_ENV=testRUN�cd�/workspace;�bundle�exec�rspec

<[email protected]>

Page 102: 이미지 기반의 배포 패러다임 Immutable infrastructure

Dockerfile.production

#�Install�bbapiADD�.�/appADD�Procfile�/app/ProcfileENV�RAILS_ENV�productionRUN�cd�/app;�bundle�install�--without�development�testRUN�cd�/app;�bundle�exec�rake�db:createRUN�cd�/app;�bundle�exec�rake�db:migrateRUN�cd�/app;�bundle�exec�rake�db:seedRUN�cd�/app/angular;�npm�installRUN�cd�/app/angular;�mkdir�tasksRUN�cd�/app/angular;�npm�install�grunt-contrib-nodeunitRUN�mv�/app/angular/config/config.default.json�/app/angular/config/config.json

#�Run�bbapiEXPOSE�3000EXPOSE�9000WORKDIR�/appCMD�foreman�start�-f�Procfile

Page 103: 이미지 기반의 배포 패러다임 Immutable infrastructure

Push�Image�to�Dokcer�Registry

mv�Dockerfile.production�Dockerfile�export�HASH=$(git�show-ref�--head�|�grep�-h�HEAD�|�cut�-d':'�-f2�|�head�-n�1�|�head�-c�10)docker�build�-rm�-t�nacyot-bbapi:${HASH}�.docker�tag�nacyot-bbapi:${HASH}�docker-registry.remotty.com/nacyot-bbapi:${HASH}docker�tag�nacyot-bbapi:${HASH}�docker-registry.remotty.com/nacyot-bbapi:latestdocker�docker-registry.remotty/nacyot-bbapi

커밋마다�빌드되어�이미지로�Registry�저장소(S3)에�저장됨.

Page 104: 이미지 기반의 배포 패러다임 Immutable infrastructure

Remote(Stage�Server)

docker�pull�docker-registry.remotty.com/nacyot-bbapi:latestdocker�run�-d�docker-registry.remotty.com/nacyot-bbapi:latest

${HASH}.stage.bbapi.remotty.com

커밋별�스테이지�서버

E2E�Test

Page 105: 이미지 기반의 배포 패러다임 Immutable infrastructure

Remote(Stage�Server)

Page 106: 이미지 기반의 배포 패러다임 Immutable infrastructure

참고�:�도커�이미지�용량?

(1�+�1�+�1�+�1�+�1�+�1�+�1)�GB�=�7GB?

Page 107: 이미지 기반의 배포 패러다임 Immutable infrastructure

참고�:�도커�이미지�용량?

$�s3cmd�du�-H���������������������������������������������1241M����s3://remotty-docker-registry/

Page 108: 이미지 기반의 배포 패러다임 Immutable infrastructure

참고�:�도커�이미지�용량?

Page 109: 이미지 기반의 배포 패러다임 Immutable infrastructure

Notify

Slack

Github

Page 110: 이미지 기반의 배포 패러다임 Immutable infrastructure

Deployment�based�on�Docker

==�Runing�Container

!=�Managing�Server

Page 111: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker�장점

컨테이너를�싣는�플랫폼

Page 112: 이미지 기반의 배포 패러다임 Immutable infrastructure

Docker�단점

컨테이너를�싣는�플랫폼

Page 113: 이미지 기반의 배포 패러다임 Immutable infrastructure

HashiCorp

Vagrant

Packer

Serf

Page 114: 이미지 기반의 배포 패러다임 Immutable infrastructure

Packer

"Packer�is�lightweight,�runs�on�every�major�operating�system,and�is�highly�performant,�creating�machine�images�for

multiple�platforms�in�parallel."

Introduction�to�Packer

Page 115: 이미지 기반의 배포 패러다임 Immutable infrastructure

Packer

한마디로

범용적�이미지�생성기

Page 116: 이미지 기반의 배포 패러다임 Immutable infrastructure

Packer

Provisioners

Chef�Solo

Ansible

Puppet

Shell�Scripts

Builders

Amazon�EC2(AMI)

Digital�Ocean

Docker

Google�Comput�Engine

VirtualBox

VMware

Page 117: 이미지 기반의 배포 패러다임 Immutable infrastructure

Vagrant�and�Packer

Development�=�Deployment�=�Image

Page 118: 이미지 기반의 배포 패러다임 Immutable infrastructure

Serf

Orchestration

Page 119: 이미지 기반의 배포 패러다임 Immutable infrastructure

"The�Future�is�Immutable"

Mitchell�Hashimoto

Page 120: 이미지 기반의 배포 패러다임 Immutable infrastructure

감사합니다�:)