CoreOS를 이용한 도커 컨테이너 배포
Docker Seoul Meetup #1 / Aug 23, 2014
!
by @subicura (김충섭)
도커로
모든 어플리케이션을
컨테이너로 만든다면
MY APPRAILS NGINX
MONGODBMYSQL RABBITMQ
서버는
도커를 돌리기 위해
존재할 뿐..
Docker 구동에 최적화된
가볍고 최소화된 모던 OS
no package manager (apt/yum)
2013년 6월부터
Alex Polvi
Brandon Philips
(rackspace)
Michael Marineau
(google)
Chrome OS를 기반으로
몇가지 기능을 추가하고
서버로 사용할 수 있도록 커스터마이징
CoreOS 특징
A Minimal Operating System Painless Updating
Docker Containers Clustered By Default
CoreOS GUI
유료!!
CoreOS 핵심구성
etcd
systemd
fleet
+ cloud-init
install
coreos-cloudinit enables a user to
customize CoreOS machines
cloud-config sample
#cloud-config
!
coreos:
etcd:
discovery: https://discovery.etcd.io/<token>
addr: $public_ipv4:4001
peer-addr: $public_ipv4:7001
fleet:
public-ip: $public_ipv4
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
users:
- name: core
coreos-ssh-import-github: subicura
vagrant
$ git clone https://github.com/coreos/coreos-vagrant.git
$ cd coreos-vagrant
$ vi user-data # edit config
$ vagrant up
*vagrant : Virtual Machine 자동 관리 툴
DEMO
etcd
A highly-available key value store
/services/app/app_1 {“ip”:”172.17.8.101”}
valuekey
directory
etcd
A highly-available key value store
Raft protocol
etcd
쉬운 API (HTTP + JSON)
SSL 보안
1000s of writes/s per instance
Watch (via HTTP long-polling)
Keys support TTL
Lock
DEMO
systemd
나아진 init system
Fedora, Gentoo, Arch 사용중 / RedHat, Debian, Ubuntu 곧
deamonize
pid
logfile path
하기쉬움
start/stop hook, audo restart…
할 필요 없음
기억할 필요 없음
기억할 필요 없음
coordination
systemd
시작 - systemctl start [service]
종료 - systemctl stop [service]
강제종료 - systemctl kill [service]
상태보기 - systemctl status [service]
로그보기 - journalctl -u [service]
sample.service
[Unit]
Description=My Service 1
Requires=docker.service
After=docker.service
!
[Service]
ExecStart=/usr/bin/docker run --rm --name app1 busybox 
/bin/sh -c "while true; do echo Hello World; sleep 1; done"
ExecStop=/usr/bin/docker kill app1
ExecStartPre / ExecStart / ExecStartPost / ExecReload / ExecStop / ExecStopPost / RestartSec
DEMO
fleet
etcd를 backend로
systemd에 custom configuration을 추가하여
service와 machine을 추상화하고
High availability를 구현함
fleet
서버리스트 - fleetctl list-machines
유닛리스트 - fleetctl list-units
시작 - fleetctl start [service]
종료 - fleetctl stop [service]
제거 - fleetctl destroy [service]
상태보기 - fleetctl status [service]
로그보기 - fleetctl journal [service]
remote
ssh-add ~/.ssh/id_rsa
export FLEETCTL_TUNNEL=172.17.8.101
sample.1.service
[Unit]
Description=My Service 1
Requires=docker.service
After=docker.service
!
[Service]
ExecStart=/usr/bin/docker run --rm --name app1 busybox 
/bin/sh -c "while true; do echo Hello World; sleep 1; done"
ExecStop=/usr/bin/docker kill app1
!
[X-Fleet]
X-Conflicts=sample.*.service
DEMO
service discovery
service discovery
database ip와 port는 뭘까?
service discovery
app의 ip와 port는 뭘까?
service discovery
Application은 자신의 IP와 PORT를 등록(registry)하고
Load Balancer는 IP와 PORT를 발견(discovery)하여
적용함
service discovery
etcd
TTL 자동으로 삭제 되는 value > 서비스가 비정상적으로 종료되었을 경우에도 체크 가능함
WATCH value 변화를 감지 > 바로바로 즉시성으로 대응 가능함
APP NGINX
APP ip/port APP ip/port
XXX ip/port NGINX ip/port
service discovery
ip port 등록
/services/app/app_1
{
“ip”: “172.17.8.101”,
“port”: “8080”
}
while true; do
etcdctl set /services/app/app_1 “{xxx}” —-ttl 60;
sleep 45;
done
service discovery
ip port 발견
/services/app/app_1
{
“ip”: “172.17.8.101”,
“port”: “8080”
}
설정 적용
upstream web_application {
<% infos.each do |info| %>
server <%= info["ip"] %>:<%= info["port"] %>;
<% end %>
}
서비스 재시작
$ nginx -s reload
sidekick
[Unit]
Description=Announce web_1
BindsTo=web.1.service
!
[Service]
ExecStart=/bin/sh -c “WEB_SERVICE_IP=$(…) && WEB_SERVICE_PORT=$
(…) && while true; do etcdctl set /services/web/web_1 "{ "ip
": "$WEB_SERVICE_IP", "port": 
"$WEB_SERVICE_PORT" }" --ttl 60; sleep 45; done"
ExecStop=/usr/bin/etcdctl rm /services/web/web_1
!
[X-Fleet]
X-ConditionMachineOf=web.1.service
DEMO
THANK YOU
!
QUESTION?

CoreOS : 설치부터 컨테이너 배포까지