Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Container CI/CD with Google Cloud Platform

Minku Lee
December 14, 2016

Container CI/CD with Google Cloud Platform

2016년 12월 14일에 있었던 Google Cloud Korea Event에서 발표했던 자료입니다. 컨테이너를 이용하여 지속적 통합(CI)과 지속적 배포(CD) 파이프라인을 구축한 사례를 공유합니다.

Minku Lee

December 14, 2016
Tweet

More Decks by Minku Lee

Other Decks in Technology

Transcript

  1. Container CI/CD with 

    Google Cloud Platform
    Minku Lee
    CTO, Shakr

    View full-size slide

  2. 맪짪펞컪짾밚힎

    View full-size slide

  3. 맪짪짝짾핂않핆

    View full-size slide

  4. 맪짪짝짾핂않핆
    GitHub
    콚큲슪큲
    핂큖앦
    펂읺쮾
    DEVELOPMENT

    View full-size slide

  5. 맪짪짝짾핂않핆
    GitHub
    콚큲슪큲
    핂큖앦
    펂읺쮾
    DEVELOPMENT
    Travis CI
    핂뻖찚슪
    퓮삩큲킲
    핂뻖핂짆힎킪
    CONTINUOUS INTEGRATION

    View full-size slide

  6. 맪짪짝짾핂않핆
    GitHub
    콚큲슪큲
    핂큖앦
    펂읺쮾
    DEVELOPMENT
    Travis CI
    핂뻖찚슪
    퓮삩큲킲
    핂뻖핂짆힎킪
    CONTINUOUS INTEGRATION
    Container 

    Registry
    핂짆힎헎핳 뫎읺
    IMAGE REGISTRY

    View full-size slide

  7. 맪짪짝짾핂않핆
    GitHub
    콚큲슪큲
    핂큖앦
    펂읺쮾
    DEVELOPMENT
    Travis CI
    핂뻖찚슪
    퓮삩큲킲
    핂뻖핂짆힎킪
    CONTINUOUS INTEGRATION
    Container 

    Registry
    핂짆힎헎핳 뫎읺
    IMAGE REGISTRY
    Compute Engine &
    Container Engine
    팮읺핂켦묺솧 뫎읺
    INFRASTRUCTURE

    View full-size slide

  8. 콚큲슪큲

    View full-size slide

  9. Pull Request읊펓

    View full-size slide

  10. .travis.yml
    sudo: required
    services:
    - docker
    before_script:
    - docker build -t videobox:$TRAVIS_BUILD_NUMBER .
    - docker images
    script:
    - docker run videobox:$TRAVIS_BUILD_NUMBER bundle exec rubocop
    - docker run videobox:$TRAVIS_BUILD_NUMBER bundle exec rspec
    - openssl aes-256-cbc -K $encrypt_key -iv $encrypt_iv -in service_account.json.enc \
    -out service_account.json -d
    - docker login -e [email protected] -u _json_key -p "$(cat service_account.json)" https://us.gcr.io
    - docker tag videobox:$TRAVIS_BUILD_NUMBER gcr.io/shakr/videobox:$TRAVIS_BUILD_NUMBER
    - docker push gcr.io/shakr/videobox:$TRAVIS_BUILD_NUMBER
    notifications:
    slack: "..."

    View full-size slide

  11. Docker 칺푷픒퓒컲헣
    sudo: required
    services:
    - docker
    핞켆헣쫂https://docs.travis-ci.com/user/docker

    View full-size slide

  12. Docker 핂짆힎찚슪
    before_script:
    - docker build -t videobox:$TRAVIS_BUILD_NUMBER .
    - docker images

    View full-size slide

  13. 헣헏슪쭒컫 퓮삩큲킲
    script:
    - docker run videobox:$TRAVIS_BUILD_NUMBER bundle exec rubocop
    - docker run videobox:$TRAVIS_BUILD_NUMBER bundle exec rspec

    View full-size slide

  14. Container Registry킪
    - docker login -e [email protected] -u _json_key \

    -p "$(cat service_account.json)" \

    https://us.gcr.io
    - docker tag videobox:$TRAVIS_BUILD_NUMBER \

    gcr.io/shakr/videobox:$TRAVIS_BUILD_NUMBER
    - docker push gcr.io/shakr/videobox:$TRAVIS_BUILD_NUMBER
    핞켆헣쫂https://cloud.google.com/container-registry/docs/advanced-authentication

    View full-size slide

  15. Container Registry킪

    View full-size slide

  16. Google Container Registry

    View full-size slide

  17. ˖ 헎핳푢믖뫊뻲풚칺푷푢믖푆쪒솒뫊믖펔픚
    ˖ 맧픎읺헒펞퓒Google Compute Engine ੋझఢझীࢲ칺푷킪

    많뻲풚뫊믖펔픚
    엖힎큲읺샎찒핳헞

    View full-size slide

  18. ˖ 헎핳푢믖뫊뻲풚칺푷푢믖푆쪒솒뫊믖펔픚
    ˖ 맧픎읺헒펞퓒Google Compute Engine ੋझఢझীࢲ칺푷킪

    많뻲풚뫊믖펔픚
    ˖ 폖많쁳콛솒퐎팖헣컿픒매묺믎픦뻲풚칺푷
    ˖ US, EU, ASIA슿펺얺읺헒힎풞
    엖힎큲읺샎찒핳헞

    View full-size slide

  19. ˖ 헎핳푢믖뫊뻲풚칺푷푢믖푆쪒솒뫊믖펔픚
    ˖ 맧픎읺헒펞퓒Google Compute Engine ੋझఢझীࢲ칺푷킪

    많뻲풚뫊믖펔픚
    ˖ 폖많쁳콛솒퐎팖헣컿픒매묺믎픦뻲풚칺푷
    ˖ US, EU, ASIA슿펺얺읺헒힎풞
    ˖ Nearline슿GCS픦헎핳펂칺푷많쁳
    엖힎큲읺샎찒핳헞

    View full-size slide

  20. gcloud CLI옪핂짆힎칺푷
    $ gcloud docker pull gcr.io/google_appengine/nodejs
    Using 'pull gcr.io/google_appengine/nodejs' for DOCKER_ARGS.
    Using default tag: latest
    latest: Pulling from google_appengine/nodejs
    a3ed95caeb02: Pull complete
    ..
    Digest: sha256:a7fcfb84b..
    Status: Downloaded newer image for gcr.io/google_appengine/
    nodejs:latest

    View full-size slide

  21. gcloud CLI 펔핂핂짆힎칺푷
    $ docker login -e [email protected] -u _json_key \

    -p "$(cat service_account.json)" \

    https://us.gcr.io
    $ docker pull gcr.io/my_gcp_project/private_image:latest
    핞켆헣쫂https://cloud.google.com/container-registry/docs/advanced-authentication

    View full-size slide

  22. Cloud Console

    View full-size slide

  23. Google Container Engine

    View full-size slide

  24. Google Container Engine
    as a service

    View full-size slide

  25. Google Container Engine
    핂뻖큲흂잏
    Container Scheduling
    핞솧핺쫃묺
    Auto-healing
    컪찒큲싢큲쩒읺
    Service Discovery
    컲헣뫎읺
    Config Management
    쭎쭒칾

    Load Balancing
    슿슿˘

    View full-size slide

  26. 컲헣폖헪pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    name: Videobox
    labels:
    name: videobox
    spec:
    containers:
    - name: videobox
    image: gcr.io/shakr/videobox:xxx
    imagePullPolicy: IfNotPresent
    env:
    - name: RACK_ENV
    value: production
    restartPolicy: Always
    dnsPolicy: default

    View full-size slide

  27. 컲헣폖헪rc.yaml
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: videobox
    spec:
    replicas: 3
    selector:
    app: videobox
    template:
    metadata:
    name: videobox
    labels:
    app: videobox
    spec:
    # Pod spec here...

    View full-size slide

  28. 퓇뫎읺콢

    View full-size slide

  29. 퓇뫎읺콢

    View full-size slide

  30. 묺컿푢콚
    Pods
    Nodes
    Replication Controllers
    Persistent Volumes
    Stateful Sets (Pet Set)
    Cron Jobs
    Secrets
    Services
    Volumes
    Replica Sets

    View full-size slide

  31. 묺컿푢콚
    Pods
    Nodes
    Replication Controllers
    Persistent Volumes
    Stateful Sets (Pet Set)
    Cron Jobs
    Secrets
    Services
    Volumes
    Replica Sets

    View full-size slide

  32. 팮읺핂켦킲믾
    Pod
    gcr.io/shakr/videobox:1

    View full-size slide

  33. 팮읺핂켦킲믾
    Pod
    gcr.io/shakr/videobox:1
    ˖ 많핳핟픎퓮삩
    ˖ 빦픎펺얺맪픦핂뻖옪묺컿
    ˖ 헎핳뫃맒뫊큲읊뫃퓮
    ˖ 짪컿홓욚킪졶슮섾핂퓮킲
    ˖ 푢킪GCS빦PersistentVolume픒칺
    푷펺섾핂읊쫂홂

    View full-size slide

  34. 팮읺핂켦킲믾
    Pod
    gcr.io/shakr/videobox:1
    Pod
    gcr.io/shakr/videobox:1
    Pod
    gcr.io/shakr/videobox:1

    View full-size slide

  35. 팮읺핂켦킲믾
    Pod
    gcr.io/shakr/videobox:1
    Pod
    gcr.io/shakr/videobox:1
    Pod
    gcr.io/shakr/videobox:1
    ReplicationController
    videobox replicas=3
    ˖ replica쿦펞싾않핞솧픊옪scale-up/
    scale-down
    ˖ k8s worker많앦킪쇦펂솒핞솧픊옪
    삲읆worker펞큲흂잏

    View full-size slide

  36. 팮읺핂켦킲믾
    Pod
    gcr.io/shakr/videobox:1
    Pod
    gcr.io/shakr/videobox:1
    Pod
    gcr.io/shakr/videobox:1
    ReplicationController
    videobox replicas=3
    Pod
    gcr.io/shakr/vault:1
    ReplicationController
    vault replicas=1

    View full-size slide

  37. ˖ 슪옪뫎읺쁢핆않큲얻(Infrastructure as Code)
    ˖ Git 슿쩒헒뫎읺킪큲뫊맧핂푷졂뫊잚헞
    홙픎헞

    View full-size slide

  38. ˖ 슪옪뫎읺쁢핆않큲얻(Infrastructure as Code)
    ˖ Git 슿쩒헒뫎읺킪큲뫊맧핂푷졂뫊잚헞
    ˖ 헣쩲섢홓콛핂펔픚 푢킪On-Premise풚옪슪퐎칺푷솒많쁳
    홙픎헞

    View full-size slide

  39. ˖ 슪옪뫎읺쁢핆않큲얻(Infrastructure as Code)
    ˖ Git 슿쩒헒뫎읺킪큲뫊맧핂푷졂뫊잚헞
    ˖ 헣쩲섢홓콛핂펔픚 푢킪On-Premise풚옪슪퐎칺푷솒많쁳
    ˖ PaaS잚큋몮 PaaS쫂삲틺맣엳믾쁳
    홙픎헞

    View full-size slide

  40. ˖ 슪옪뫎읺쁢핆않큲얻(Infrastructure as Code)
    ˖ Git 슿쩒헒뫎읺킪큲뫊맧핂푷졂뫊잚헞
    ˖ 헣쩲섢홓콛핂펔픚 푢킪On-Premise풚옪슪퐎칺푷솒많쁳
    ˖ PaaS잚큋몮 PaaS쫂삲틺맣엳믾쁳
    ˖ master/worker뽆슪뫎읺많푢펔쁢잲삖힎슪컪찒큲
    홙픎헞

    View full-size slide

  41. ˖ Preemptible VM픒핂푷찒푷헖맞핂쭖많쁳
    ˖ PVM Node Pool (Beta)많헣킫킪쇦졂멾폖헣
    몮짊섦헞

    View full-size slide

  42. ˖ Preemptible VM픒핂푷찒푷헖맞핂쭖많쁳
    ˖ PVM Node Pool (Beta)많헣킫킪쇦졂멾폖헣
    ˖ 퀺풂폲큲핊잏핂쭖많쁳
    ˖ Cluster Autoscaler (Beta)많헣킫킪쇦졂멾폖헣
    몮짊섦헞

    View full-size slide

  43. ˖ Preemptible VM픒핂푷찒푷헖맞핂쭖많쁳
    ˖ PVM Node Pool (Beta)많헣킫킪쇦졂멾폖헣
    ˖ 퀺풂폲큲핊잏핂쭖많쁳
    ˖ Cluster Autoscaler (Beta)많헣킫킪쇦졂멾폖헣
    ˖ 싢큲(>50GB per pod)읊푢옪쁢핂뻖읊풂폏믾슺
    ˖ 솧헏큲앦싢큲빦몮컿쁳Local SSDܳPod쪒옪샇쿦펔픚
    몮짊섦헞

    View full-size slide

  44. Google Compute Engine
    with containers!

    View full-size slide

  45. Container-Optimized OS (BETA)

    View full-size slide

  46. ˖ Chromium OS 믾짦 Verified Boot
    ˖ Active-passive픦핞솧펓섾핂힎풞
    ˖ systemd 칺푷
    ˖ cloud-init힎풞
    ˖ 핊쭎싢엗읺읊헪푆욶핊킪큲핂핋믾헒푷
    ˖ 힎잲삖헎펔픚핂뻖뺂펞컪팮읺핂켦픒킲쁢멑핂믾쫆
    ˖ 읺뿓큲짾뫊삲읂멚Google핂헣킫힎풞
    Container-Optimized OS (BETA)

    View full-size slide

  47. gcloud CLI옪핆큲큲캫컿
    $ gcloud compute instances create gci-instance-test \
    --image-project google-containers \
    --image-family gci-stable \
    --zone asia-northeast1-a \
    --machine-type n1-standard-1

    View full-size slide

  48. cloud-init
    $ gcloud compute instances create gci-instance-test \
    --image-project google-containers \
    --image-family gci-stable \
    --zone asia-northeast1-a \
    --machine-type n1-standard-1 \
    --metadata-from-file user-data=cloud-init.yml

    View full-size slide

  49. cloud-init.yml
    #cloud-config
    users:
    - name: myservice
    uid: 2000
    write_files:
    - path: /etc/systemd/system/myservice.service
    permissions: 0644
    owner: root
    content: |
    [Unit]
    Description=Start a simple docker container
    [Service]
    ExecStartPre=/usr/share/google/dockercfg_update.sh
    ExecStart=/usr/bin/docker run --rm -u 2000 --net=host --name=myservice -e RACK_ENV=production -p 80:80 \
    gcr.io/project/myservice:latest
    ExecStop=/usr/bin/docker stop myservice
    ExecStopPost=/usr/bin/docker rm myservice
    runcmd:
    - systemctl daemon-reload
    - systemctl enable myservice.service
    - systemctl start myservice.service

    View full-size slide

  50. ˖ 믾홂VM뫎읺짷킫픒믆샎옪헏푷많쁳
    ˖ Preemptible VM, Regional Managed Instance Group ١
    ˖ 핊짦헏핆읺뿓큲짾쫂삲폲쩒슪많헏픚
    ˖ Kubernetes펞핃쿧힎믾헒펞솒핓많쁳
    홙픎헞

    View full-size slide

  51. 맪짪짝짾핂않핆
    GitHub
    콚큲슪큲
    핂큖앦
    펂읺쮾
    DEVELOPMENT
    Travis CI
    핂뻖찚슪
    퓮삩큲킲
    핂뻖핂짆힎킪
    CONTINUOUS INTEGRATION
    Container 

    Registry
    핂짆힎헎핳 뫎읺
    IMAGE REGISTRY
    Compute Engine &
    Container Engine
    팮읺핂켦묺솧 뫎읺
    INFRASTRUCTURE

    View full-size slide

  52. Google Cloud Platform
    о੢ খࢶ ஶప੉ց ӝࣿਸ ࡅܰҊ औѱ ੸ਊ оמೠ ೒ۖಬ

    View full-size slide

  53. Thank you
    We're looking for talented engineers! 쁳엳핖쁢펢힎삖펂읊졶킻삖삲
    Minku Lee [email protected]

    View full-size slide