ImmutableInfrastructure
DaekwonKim
propellerheaven@gmail.com
nacyot
@nacyot
Rubyprogrammer
http://nacyot.com
WebDevelopment
RubyonRails
ProgrammingLanguages
Visualization
Translation
Deployment
Deployment
ImmutableInfrastructure
Leevi
http://leevi.co.kr/
Remotty
http://blog.remotty.com
지난이야기
WebDevelopment
ServerManagement
AmazonWebService
오늘이야기
ImmutableInfrastructure
DisposableComponents
Orchestration
BlueGreenDeployment
ContinuousDelivery
새로운툴
Chef/Puppet/Ansible
Docker
Vagrant
Packer
Serf
ServerSpec
AmazonWebService
TOC
Cloud
AutoScaling
Image
Deploy
ImmutableInfrastructure
DisposableComponents
ConfigurationManagement
Docker
HashiCorp
Cloud
SaaS
PasS
IaaS
Cloud
SoftwareasaService
GoogleApps
AdobeCreativeCloud
PlatformasaService
Heroku
GoogleAppEngine
InfrastructureasaService
AmazonWebService
Ucloudbiz
PlatformasaService
컴퓨터vs클라우드
컴퓨터(서버)
물리적실체
공간적제약
장소적제약
예산적제약
유지보수
클라우드위의컴퓨터
비물리적실체
공간적제약?
장소적제약?
예산적제약?
유지보수?
Delegate,Delegate,Delegate
공간적제약
언제든원하는만큼사용할수있음
물리적서버를설치할필요없음
장소적제약
원하는리젼(장소)에서서비스가능
AWSEC2,DigitalOcean
원하는위치에서배포가능
CDN,AWSCloudFront
예산적제약
매몰비용이거의발생하지않음
서버를구입할필요없음
월단위대여할필요없음
사용한만큼만내면됨
시간단위과금
유지보수
필요없음
DisposableComponents?
AmazonWebService는인터넷의발전소다.
타마카와켄
디지털오션예제
서버실행하기
$tugboatcreateContainerShip-s66-i2158507-r6-k301023
$tugboatdroplets
ContainerShip(ip:128.199.253.99,status:new,region:6,id:1383635)
서버종료하기
$tugboatdestroyContainerShip
Dropletfuzzynameprovided.FindingdropletID...done,1383635(ContainerShip)
Warning!Potentiallydestructiveaction.Pleaseconfirm[y/n]:y
Queuingdestroyfor1383635(ContainerShip)...done
Billing
10원
Cloud!=ServerHosting
RRRSpec
분산테스트프레임워크
RRRSpec
테스트17000개
1대로몇시간걸림
RRRSpec
1대*몇시간
==
EC2스팟인스턴스60대*8~9분
DeploymentonCloud
AutoScaling
부하가커지면
자동적으로인스턴스가실행되고(ScaleOut)
부하가작아지면
자동적으로인스턴스가종료됨
AutoScaling의장점
유연한대응
합리적비용
AutoScaling의조건
어플리케이션설계
정교한비지니스로직분리
서버환경설정분리및자동화
데이터스토어분리
WheninRome,doastheRomansdo
클라우드위에선클라우드에어울리는설계가필요
BestPractice
CDP클라우드설계원칙
TheTwelve-FactorApp
CDP클라우드설계원칙
가능한한서비스를이용
생각보다행동으로
작은규모로시작하여스케일아웃
변화를전계층에서처리
고장을위한설계
처음뿐이아닌주기적인개선
AutoScaling을전제로한컴퓨터란
어플리케이션이가동되기위한환경이구성된
인스턴스로부터Stamp패턴으로생성된
AMI이미지로부터생성된
가상인스턴스(컴퓨터)
AutoScaling을전제로한컴퓨터란
어플리케이션이가동되기위한환경이구성된
인스턴스로부터Stamp패턴으로생성된
AMI이미지로부터생성된
DisposableComponents
DisposableCopmonent
쓰고
버리는
DisposableCopmonent
미리설정된
쓰고
버리는
인스턴스(컴퓨터)
DisposableCopmonent
서버설정?
서버관리?
Image
Image
새로운문제
Image
이미지는정말로작동가능한가?
Image
아마도…
최초의이미지는어디서오는가?
서버설정
useradd…
setenv
apt-getupdate
apt-getinstall…(순서!!)
ufw…
iptable…
…
최초의이미지는어디서오는가?
어플리케이션설치
rubybuild
apt-get…
geminstallbundler
gitclone…
bundleinastll
configuration
runapplicationserver
serverproxy
…
어플리케이션이업데이트되면?
어플리케이션업데이트
gitpull…
apt-get…
bundleupdate
configuration
…
유지보수
Thesystembecomesahouseofcards.Youfearanychange
andyoufearreplacingitsinceyoudon’tknoweverything
abouthowitworks.
TrashYourServersandBurnYourCode:ImmutableInfrastructureand
DisposableComponents,ChadFowler
서버관리의본질은전역적환경설정
서버는
하드웨어부터
OS를거쳐
어플리케이션까지
모든요소들이얽히고섥혀있는곳
의존성거의관리불가능
StatefulImage
그저이미지화했을뿐이고
StatefulImage
복원불가능
검증불가능
일단돌아는감
안전불감증
StatefulImage
DisposableComponents
fromRecycledImage
State
프로그래머의원죄
전역변수를사용하지말라
ConfigurationManagement
상태관리가귀찮으면관리안하면되잖아
이토나오야
InfrastructureasCode
이토나오야
ConfigurationManagement
Chef
Puppet
Ansible
ConfigurationManagement
Idempotence(멱등)
ConfigurationManagement
복원가능
Build
검증가능
Serverspec
이력관리
InfrastructureasCode
Build
#ChefCookbook::MyServer
#Recipe::InstallApache
log'InstallApache'
package'httpd'do
action:install
end
ServerSpec
require'spec_helper'
describepackage('httpd')do
it{shouldbe_installed}
end
describeservice('httpd')do
it{shouldbe_enabled}
it{shouldbe_running}
end
describeport(80)do
it{shouldbe_listening}
end
ConfigurationManagement
Deployment
Vagrant
Provisioner
Provider
Vagrant
Provisioner=Chef
Provider=Vmware
Vagrant
Provisioner=Chef
Provider=AWSEC2
Vagrant
Provisioning=Chef
Provider=DigitalOcean
Vagrant
HashiCorp의야망
Vagrant
뒤에서다시
ServerImage
Stateless
ConfigurationManagement
ImmutableInfrastructure
Immutable?
변경불가능
inJava
StringvsStringBuffer
함수형프로그래밍언어
Immutable==Stateless
TravisCI
커밋할때마다
새로운빌드환경구축
Heroku
푸쉬할때마다
새로운어플리케이션이미지생성
ImmutableInfrastructure
관리가능하고
ConfigurationManagement
ImmutableInfrastructure
테스트가능한
ServerSpec
ImmutableInfrastructure
Stateless하고
Build
ImmutableInfrastructure
Scalable한
StampPattern
ImmutableInfrastructure
이미지기반의
Lightweight,Portable
ImmutableInfrastructure
관리가능하고
테스트가능하며
Stateless하고
Scalable한
이미지기반의
어플리케이션배포
Docker
Dockerisanopen-sourceenginethatautomatesthe
deploymentofanyapplicationasalightweight,portable,self-
sufficientcontainerthatwillrunvirtuallyanywhere
Docker
한마디로
BuildOnce,RunAnywhere
Docker
Docker
Image
Container
Dockerfile
DockerImage
Build
Dockerfile
FROMubuntu:12.04
MAINTAINERDaekwonKim
#Runupgrade
RUNechodebhttp://archive.ubuntu.com/ubuntuprecisemainuniverse/etc/apt/sources.list
RUNapt-getupdate
#Installbasicpackages
RUNapt-get-qq-yinstallgitcurlbuild-essential
#Installapache2
RUNapt-get-qq-yinstallapache2
ENVAPACHE_RUN_USERwww-data
ENVAPACHE_RUN_GROUPwww-data
ENVAPACHE_LOG_DIR/var/log/apache2
RUNa2enmodrewrite
propellerheaven@gmail.com
DockerContainer
Run
Docker-registry
ImageArchive
예제)Remotty공동가계부빌드/배포구상도
GithubHook
Jenkins
Local
PushImagetoDockerRegistry
Remote(StageServer)
Notify
Local(BuildServe)
DockerBuild(test)
DockerBuild(application)
PushImagetoDockerRegistry
Dockerfile
FROMnacyot-bbapi
MAINTAINERDaekwonKim
ADD./workspace
#ENV
ENVRAILS_ENVtest
#Build
RUNcd/workspace;echo'gem:--no-ri--no-rdoc'~/.gemrc
RUNcd/workspace;bundleinstall--withoutdevelopment
RUNcd/workspace;bundleexecrakedb:migrateRAILS_ENV=test
RUNcd/workspace;bundleexecrspec
propellerheaven@gmail.com
Dockerfile.production
#Installbbapi
ADD./app
ADDProcfile/app/Procfile
ENVRAILS_ENVproduction
RUNcd/app;bundleinstall--withoutdevelopmenttest
RUNcd/app;bundleexecrakedb:create
RUNcd/app;bundleexecrakedb:migrate
RUNcd/app;bundleexecrakedb:seed
RUNcd/app/angular;npminstall
RUNcd/app/angular;mkdirtasks
RUNcd/app/angular;npminstallgrunt-contrib-nodeunit
RUNmv/app/angular/config/config.default.json/app/angular/config/config.json
#Runbbapi
EXPOSE3000
EXPOSE9000
WORKDIR/app
CMDforemanstart-fProcfile
PushImagetoDokcerRegistry
mvDockerfile.productionDockerfile
exportHASH=$(gitshow-ref--head|grep-hHEAD|cut-d':'-f2|head-n1|head-c10)
dockerbuild-rm-tnacyot-bbapi:${HASH}.
dockertagnacyot-bbapi:${HASH}docker-registry.remotty.com/nacyot-bbapi:${HASH}
dockertagnacyot-bbapi:${HASH}docker-registry.remotty.com/nacyot-bbapi:latest
dockerdocker-registry.remotty/nacyot-bbapi
커밋마다빌드되어이미지로Registry저장소(S3)에저장됨.
Remote(StageServer)
dockerpulldocker-registry.remotty.com/nacyot-bbapi:latest
dockerrun-ddocker-registry.remotty.com/nacyot-bbapi:latest
${HASH}.stage.bbapi.remotty.com
커밋별스테이지서버
E2ETest
Remote(StageServer)
참고:도커이미지용량?
(1+1+1+1+1+1+1)GB=7GB?
참고:도커이미지용량?
$s3cmddu-H
1241Ms3://remotty-docker-registry/
참고:도커이미지용량?
Notify
Slack
Github
DeploymentbasedonDocker
==RuningContainer
!=ManagingServer
Docker장점
컨테이너를싣는플랫폼
Docker단점
컨테이너를싣는플랫폼
HashiCorp
Vagrant
Packer
Serf
Packer
Packerislightweight,runsoneverymajoroperatingsystem,
andishighlyperformant,creatingmachineimagesfor
multipleplatformsinparallel.
IntroductiontoPacker
Packer
한마디로
범용적이미지생성기
Packer
Provisioners
ChefSolo
Ansible
Puppet
ShellScripts
Builders
AmazonEC2(AMI)
DigitalOcean
Docker
GoogleComputEngine
VirtualBox
VMware
VagrantandPacker
Development=Deployment=Image
Serf
Orchestration
TheFutureisImmutable
MitchellHashimoto
감사합니다:)

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