Slide 1

Slide 1 text

Deploying a Containerized Application on Google Kubernetes Engine Masayuki Hayasida Software Developer at Framgia.Inc 2017/12/23

Slide 2

Slide 2 text

self-introduction Software Engineer Framgia.Inc ɾ࠷ۙԬࢁҾͬӽ͖ͯͨ͠ ɾϑϧϦϞʔτϫʔΧʔ
 ɾ޷͖ͳٕज़ 
 - Frontend(react, redux, angular)
 - Infrastructure(GCP, AWS, Azure, VPS…)
 - GAS, Slack, Serverless… ୲౰ྖҬ͸͜ͷ΁Μ

Slide 3

Slide 3 text

today’s topic ɾWhat’s kubernetes ɾWhat’s GKE
 ɾHow to provide an application on GKE ɾOthers

Slide 4

Slide 4 text

Kubernetes

Slide 5

Slide 5 text

What’s Kubernetes ? Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. ɾAutomatic binpacking ɾHorizontal scaling ɾAutomated rollouts and rollbacks ɾStorage orchestration ɾSelf-healing ɾService discovery and load balancing ɾSecret and configuration management ɾBatch execution

Slide 6

Slide 6 text

Α͏͢Δʹɺɺ ίϯςφΫϥελϚωʔδϟͰ͢ 
 ɾίϯςφͷΦʔτεέʔϧ ɾϦιʔεεέδϡʔϧ ɾϩʔυόϥϯγϯά ɾetc…

Slide 7

Slide 7 text

How can I use Kubernetes ? ɾGCP (Compute Engine, Kubernetes Engine) ɾAWS (AmazonEC2, AmazonEKS new! ) ɾAzure(Azure Container Service) ɾIBM Blue Mix
 ɾetc… ϚωʔδυͰͳͯ͘ɺselfhost͢Δ͜ͱ΋Մೳɻ ͯͬͱΓ͹΍͘͸͡ΊΔʹ͸ύϒϦοΫΫϥ΢υΛ࢖ͬͨํָ͕ʹߏஙͰ͖Δ

Slide 8

Slide 8 text

Kubernetes Architecture

Slide 9

Slide 9 text

Kubernetes Architecture

Slide 10

Slide 10 text

Pod / Deployment

Slide 11

Slide 11 text

Pod / Deployment PodɿίϯςφΛάϧʔϐϯάԽͨ֓͠೦ Deployment: PodΛ্ཱͪ͛ͷఆ͚ٛͮΛͨ͠΋ͷ - template: Podఆٛ - replicas: Podͷಉ࣌ىಈ਺Λఆٛ and keep PodͷϨϓϦΧ਺্ݶ͸NodeͷεϖοΫʹґଘ͢Δ - image: docker image file 
 ӈͷྫͰ͸ɺnginxͷPodΛport:80Ͱ3ͭͨͪ͋͛ͯʔ 
 


Slide 12

Slide 12 text

kubernetesͷૢ࡞͸ɺkubectl

Slide 13

Slide 13 text

Service

Slide 14

Slide 14 text

Service - ओʹ಺෦తͳωοτϫʔΫ؅ཧΛߦ͏ - τϥϑΟοΫͷड෇Λ୲͏ΞΫηείϯτϩʔϥ ಉҰͷPodʹ୅දIPΛ͚ͭͯ;ΓΘ͚Δ ͖͞΄ͲͷnginxPodͷϨϓϦΧ3ͭ ͍͍ײ͡ʹ;ΓΘ͚ͯʔ

Slide 15

Slide 15 text

Ingress

Slide 16

Slide 16 text

Ingress - άϩʔόϧͷϩʔυόϥϯαΛఆٛ - HOST΍TLSઃఆΛ͢Δ - ΞΫηεϧʔϧͷઃఆ͕Մೳ
 όʔνϟϧϗετ΍URLʹΑΔ
 αʔϏε΁ͷ;ΓΘ͚ ར༻ྫɿ - ෳ਺։ൃػͰαϒυϝΠϯຖʹ
 ΞΫηεϧʔϧΛ࡞੒ - ຊ൪ػ / ։ൃػΞΫηεΛৼΓ෼͚

Slide 17

Slide 17 text

Kubernetes

Slide 18

Slide 18 text

Kubernetes on GKE

Slide 19

Slide 19 text

Kubernetes on GKE

Slide 20

Slide 20 text

GKE is … ɾΫϥελͷૢ࡞͸GCP-SDKͷgcloudͰૢ࡞

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

࣮ྫɿࣗࣾαʔϏε

Slide 23

Slide 23 text

GCP Architecture

Slide 24

Slide 24 text

Main Application

Slide 25

Slide 25 text

Main Application

Slide 26

Slide 26 text

Nginx /healthz Ͱ Ϩεϙϯε200Λ͔͑ͯ͋͛͠Δ

Slide 27

Slide 27 text

Rolling Update ஈ֊తʹPodΛ͍Ε͔͑ͯ͘ΕΔɻ μ΢ϯλΠϜθϩํࣜ

Slide 28

Slide 28 text

Puma / Sidekiq

Slide 29

Slide 29 text

Secrets / ConfigMap ɾconfϑΝΠϧ͸ docker಺ʹ;͘Ίͣɺ volumeΛϚ΢ϯτͯ͠࢖͏

Slide 30

Slide 30 text

- db:migrate΍assets-precompile౳ͷrakeλεΫશൠ͸JobͰߦ͏ 
 - db-migrationΛ͢ΔPodΛͨͪ͋͛ - rakeλεΫΛ࣮ࢪɺͦͯ͠໾໨Λ͸ͨͯ͠ࢮΜͰ͍͘ Job

Slide 31

Slide 31 text

Job Script

Slide 32

Slide 32 text

ఆظతʹ࣮ߦ͢ΔJob΍ɺϐϯϙΠϯτͷ࣌ؒଳʹ࣮ߦ͍ͨ͠৔߹͸CronJobΛ࢖͏ ਂ໷ͷrakeλεΫʢఆظతͳΫϦʔχϯάॲཧʣΛCronJobͰ࣮ߦ͍ͯ͠Δ CronJob

Slide 33

Slide 33 text

- VolumeϑΝΠϧΛComputeEngineͷDisk͔ΒऔಘͰ͖Δ - Pod͔ΒಡΈࠐΉͱ͖͸readonly ͳͷͰɺผdiskΛऔಘ͠ɺPodΛ࠶࡞੒͢Δͱ͔͍͏ΊΜͲ ͍͘͜͞ͱΛ͠ͳ͚Ε͹ͳΒͳ͍ R/W͠ͳ͕ΒӬଓԽ͍ͨ͠ʹ೉͋Γ GCEPersitentDisk / assets:precompile

Slide 34

Slide 34 text

ͨͩ͠ʂʂʂʂ υΩϡϝϯτൈਮ

Slide 35

Slide 35 text

Ͳ͏͢Δʁʁ

Slide 36

Slide 36 text

https://github.com/kubernetes/examples/blob/master/staging/volumes/nfs/README.md NFS NFSαʔόΛؒʹ͸͞Ήͱෳ਺ϙουͰ΋R/WͰϘϦϡʔϜར༻͕Մೳ

Slide 37

Slide 37 text

Build / Deploy

Slide 38

Slide 38 text

Build / Deploy

Slide 39

Slide 39 text

Private Registory

Slide 40

Slide 40 text

Container Registry / Cloud Container Builder 
 - KMSʹΑΔɺconfig/database.ymlͷෳ߹ - KMSʹΑΔɺconfig/secrets.ymlͷෳ߹ - migration - docker build and push GCR - kubectl set image - slack notifications

Slide 41

Slide 41 text

Container Registry / Cloud Container Builder

Slide 42

Slide 42 text

Container Registry / Cloud Container Builder

Slide 43

Slide 43 text

Logging / Monitoring

Slide 44

Slide 44 text

Logging / Monitoring

Slide 45

Slide 45 text

- ඪ४ग़ྗͨ͠΋ͷ͸શͯɺStackdriver΁ग़ྗ͞ΕΔ - Stackdriver͔ΒStackdriverMonitoring΁ͷ࿈ܞ - ϩάͷܗࣜ͸JSON͕Α͍ - Stackdriverͷϩάσʔλ͸ҎԼͷGCPαʔϏε΁࿈ܞՄೳ - Cloud Pub/Sub - Cloud Storage - BigQuery Logging(Stackdriver)

Slide 46

Slide 46 text

Stackdriver -> PubSub-> ElasticStack - PubSubͰlogstashͷpiplineʹϩάΛྲྀ͜͠Έɺ
 Elasticserchʹͱ͹ͯ͠ɺkibanaͰՄࢹԽʂ - ओʹো֐ௐࠪ༻్

Slide 47

Slide 47 text

Stackdriver -> BigQuery -> DataStudio

Slide 48

Slide 48 text

Monitoring (Prometheus * Grafana) - Pod୯ҐͰੑೳ؂ࢹ͕Ͱ͖Δɻଟ࠼ͳMetrics - OpenMetricsͱͯ͠ͷσϑΝΫτʹͳΓͦ͏ - ԼͷΩϟϓνϟͷΑ͏ʹɺͳʹΑΓGrafanaΧοίΠΠΑͯ͘
 ςϯγϣϯ͕͕͋Δɻ΋ͪΖΜAlertઃఆͰSlack௨஌΋Մೳ

Slide 49

Slide 49 text

࢖ͬͯͳ͍͕ɺҰԠػೳΛONʹ͍ͯ͠Δ
 Monitoring (Stackdriver)

Slide 50

Slide 50 text

ɾSpinnecker, Istio, gRPCͳͲར༻͠ ϚΠΫϩαʔϏεԽΛ͢͢ΊΔ ࠓޙ΍Γ͍ͨ͜ͱ

Slide 51

Slide 51 text

ɾ·ͱΊKubernetesΛͯͬͱΓ͹΍͘
 ͸͡ΊΔͷʹGKE͸࠷ద ɾҰ౓ఆٛϑΝΠϧΛ࡞Ε͹
 ผϓϩδΣΫτͰ΋ԣஅతʹ࢖͑Δ ɾେྔͷτϥϑΟοΫ͕͋ΔطଘαʔϏεͰ
 ͷҠߦ͸৻ॏʹ ɾGAE΍HerokuͰಈ͍͍ͯΔΞϓϦΛ ·ͣ͸Ҡߦͯ͠Έͯӡ༻ͯ͠ΈΔͷ͕ϕλʔ ·ͱΊ

Slide 52

Slide 52 text

͓ΘΓ