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

kubernetesで変わる開発スタイル 〜マイクロサービスじゃなくてもいいじゃない〜

kubernetesで変わる開発スタイル 〜マイクロサービスじゃなくてもいいじゃない〜

PHP Conference 2016の発表資料です
kubernetesをつかってゲーム開発の
開発スタイルを変えたお話です

CyberAgent SGE Engineer

November 02, 2016
Tweet

More Decks by CyberAgent SGE Engineer

Other Decks in Technology

Transcript

  1. • גࣜձࣾαΠόʔΤʔδΣϯτ • 4(&౷ׅຊ෦ٕज़౷ׅࣨ$50 • നҪɹӳ • ΤϯδχΞ • 5XJUUFS

    !HPPEPP • #MPH IUUQBNFCMPKQHPPEPP • %2 ͙ͪ͢Ή '# ϓΫϦϙ ཱྀܳਓ ͓લɺ୭Α
  2. LVCFSOFUFTͷಛ௃  ɾ/PEFͷ଱ো֐ੑ Deployment - replicas: 2 cluster - NUM_NODES:3

    ࣗಈͰSFQMJDBΛ̎ʹอͭΑ͏ʹ 1PE͕ผͷ/PEF্ʹੜ੒͞ΕΔ
  3. LVCFSOFUFTͷಛ௃  ɾ3PMMJOH6QEBUF Deployment - replicas: 2 - strategy -

    type: RollingUpdate ৽͍͠ίϯςφΛద༻͢Δ kubectl apply -f new-deployment.yaml
  4. LVCFSOFUFTͷಛ௃  ɾ3PMMJOH6QEBUF Deployment - replicas: 2 - strategy -

    type: RollingUpdate Ұ౓ʹ࡞੒͞ΕΔ1PEͷ਺͸ Ͱௐ੔Մೳ ˞ࠓճ͸૝ఆ .spec.strategy.rollingUpdate.maxSurge
  5. LVCFSOFUFTͷಛ௃  ɾ*OHSFTTͰͷ෼ࢄ blue.example.com green.example.com Ingress - rules - host:blue.example.com

    - http.paths.backend - serviceName: blue-service - host:green.example.com - http.paths.backend - serviceName: green-service Service - name: blue-service Service - name: green-service
  6. ࢼͨ͜͠ͱ  ɾ*OHSFTTͰͷ੾ସ blue.example.com Ingress - rules - host:blue.example.com -

    http.paths.backend - serviceName: blue-service Service - name: blue-service
  7. ɾ*OHSFTTͰͷ੾ସ blue.example.com Service - name: blue-service Service - name: green-service

    ࢼͨ͜͠ͱ  Ingress - rules - host:blue.example.com - http.paths.backend - serviceName: blue-service ৽͍͠ίϯςφΛద༻͢Δ kubectl apply -f green-service.yaml
  8. ɾ*OHSFTTͰͷ੾ସ blue.example.com Service - name: blue-service Service - name: green-service

    ࢼͨ͜͠ͱ  Ingress - rules - host:blue.example.com - http.paths.backend - serviceName: green-service *OHSFTTΛߋ৽
  9. ݁Ռɿࣦഊ w͕Ͱͯ͠·ͬͨ wMJWFOFTT1SPCFɺSFBEMJOFTT1SPCF͸ઃఆࡁΈ apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-green

    spec: replicas: 3 spec: containers: - name: nginx-green image: nginx ports: - containerPort: 80 livenessProbe: httpGet: path: /index.html port: 80 initialDelaySeconds: 30 timeoutSeconds: 1 readinessProbe: httpGet: path: /index.html port: 80 ˞ઃఆ্͸͏·͍͖ͦ͘͏Ͱ͕͢ɺͲ͔ؒ͜ҧ͍ͬͯΔͷ͔΋
  10. ɾ*OHSFTTͰͷ੾ସ Service - name: blue-service Service - name: green-service ࢼͨ͜͠ͱ

     green.goodoo.tech blue.goodoo.tech Ingress - rules - host:blue.goodoo.tech - http.paths.backend - serviceName: blue-service - host:green.goodoo.tech - http.paths.backend - serviceName: green-service
  11. ɾ*OHSFTTͰͷ੾ସ blue.goodoo.tech Service - name: blue-service Service - name: green-service

    ࢼͨ͜͠ͱ  Ingress - rules - host:blue.goodoo.tech - http.paths.backend - serviceName: green-service - host:green.goodoo.tech - http.paths.backend - serviceName: green-service green.goodoo.tech *OHSFTTΛߋ৽
  12. ɾ4FSWJDFͰͷ੾ସ ࢼͨ͜͠ͱ  blue.goodoo.tech Deployment - labels: - app:nginx-blue Deployment

    - labels: - app:nginx-green Service - selector - app: nginx-blue Service - selector: - app: nginx-blue
  13. ɾ4FSWJDFͰͷ੾ସ ࢼͨ͜͠ͱ  blue.goodoo.tech Deployment - labels: - app:nginx-blue Deployment

    - labels: - app:nginx-green 4FSWJDFΛߋ৽ Service - selector - app: nginx-green Service - selector: - app: nginx-blue
  14. ϩʔΧϧͷ։ൃ؀ڥ minikube ϩʔΧϧ1$ ϗετ Service Service - name: mysql-service -

    type: NodePort - ports - nodePort: 31101 192.168.99.100 192.168.99.100:31101 ϩʔΧϧ1$͔Β͸ /PEF1PSUͰࢦఆ͞ΕͨϙʔτͰ઀ଓՄೳ ˎ7JSUVBM#PY͔Βׂ౰ΒΕΔ mysql -h 192.168.99.100 --port 31101
  15. ίϯςφ͸ΦϦδφϧͰ͸ͭ͘Βͳ͍ ެࣜΠϝʔδ͔Βͭ͘Δ ίϯςφ࡞੒ͷઓུ FROM nginx:1.10.1 RUN rm /etc/nginx/conf.d/default.conf ADD ./conf.d/

    /etc/nginx/conf.d ADD ./ssl/ /etc/ssl Dockerfile wDPOGΛॻ͖׵͑Δఔ౓ wϕʔεͷίϯςφͷ࡞੒ʹίετ Λ͔͚ͳ͍ wϕʔεͷίϯςφͷόʔδϣϯΞ οϓ͕༰қ
  16. ੩తΞυϨεͱυϝΠϯΛ݁ͼ͚ͭͨ͋ͱ ੩తΞυϨεͰ*OHSFTTΛϧʔςΟϯά͍ͨ͠ *OHSFTTͱυϝΠϯ ˞ී௨ͷ͜ͱͰ͕͢ɺ͸·ͬͨͷͰɾɾɾ λΠϓΛάϩʔόϧʹͯ͠ ੩తΞυϨεΛ༧໿͢Δ apiVersion: extensions/v1beta1 kind: Ingress

    metadata: name: static-ip annotations: kubernetes.io/ingress.global-static-ip-name: gke-phpcon-lb Ingress.yaml BOOPUBUJPOTͰ੩తΞυϨεͷ໊લΛ ࢦఆ͢Δ
  17. ΞϓϦͷόʔδϣϯຖʹαʔόΛΘ͚Δ Service - name: app-v2 Service - name: app-v1 *OHSFTTͰϧʔςΟϯά

    goodoo.tech/v1 goodoo.tech/v2 apiVersion: extensions/v1beta1 kind: Ingress metadata: name: routing spec: rules: - host: goodoo.tech http: paths: - path: /v1 backend: serviceName: app-v1 - path: /v2 backend: serviceName: app-v2 Ingress.yaml ϓϩάϥϜ಺ʹόʔδϣϯ෼͚ͷJGจ͕͍Βͳ͍
  18. /PEF1PPMΛ࢖͏ blue.example.com Service - name: blue-service ແఀࢭͰͷόʔδϣϯΞοϓ Node Pool v1.3

    ৽ن/PEF1PPMΛ࡞੒ gcloud container node-pools create --num-nodes=2 ˞৽ن/PEF1PPM͸࠷৽ͷόʔδϣϯͰ࡞੒͞ΕΔ Node Pool v1.4
  19. /PEF1PPMΛ࢖͏ blue.example.com Service - name: blue-service ແఀࢭͰͷόʔδϣϯΞοϓ Node Pool v1.3

    ݹ͍όʔδϣϯͷ/PEF1PPMͰ ৽ن1PE͕࡞੒͞Εͳ͍Α͏ʹ͢Δ DPSEPO kubectl cordon node-pool-v1.3-node1 kubectl cordon node-pool-v1.3-node2 ˞/PEFຖʹࢦఆ͢Δ Node Pool v1.4
  20. /PEF1PPMΛ࢖͏ blue.example.com Service - name: blue-service ແఀࢭͰͷόʔδϣϯΞοϓ Node Pool v1.3

    /PEF্ͷ1PEΛҠಈͤ͞Δ ESBJO kubectl drain node-pool-v1.3-node1 ˞/PEF୆ͣͭ Node Pool v1.4 drain
  21. /PEF1PPMΛ࢖͏ blue.example.com Service - name: blue-service ແఀࢭͰͷόʔδϣϯΞοϓ Node Pool v1.3

    /PEF্ͷ1PEΛҠಈͤ͞Δ ESBJO kubectl drain node-pool-v1.3-node2 ˞/PEF୆ͣͭ Node Pool v1.4 drain drain
  22. /PEF1PPMΛ࢖͏ blue.example.com Service - name: blue-service ແఀࢭͰͷόʔδϣϯΞοϓ Node Pool v1.3

    ࠷ޙʹݹ͍όʔδϣϯͷ /PEF1PPMΛ࡟আ͢Δ gcloud container node-pools delete node-pool-v1.3 Node Pool v1.4
  23. Node Pool app-v1 Node Pool app-v1.1 σϓϩΠ͚࣌ͩ/PEFΛεέʔϧͤ͞Α͏  ৽͍͠ίϯςφ༻ͷ /PEF1PPMΛ࡞੒͢Δ

    goodoo.tech Service - name: app-v1 gcloud container node-pools create --num-nodes=2 --node-labels=app-v1.1
  24. Node Pool app-v1 Node Pool app-v1.1 σϓϩΠ͚࣌ͩ/PEFΛεέʔϧͤ͞Α͏  goodoo.tech Service

    - name: app-v1 ৽͍͠ίϯςφΛσϓϩΠ Service - name: app-v1.1
  25. Node Pool app-v1 Node Pool app-v1.1 σϓϩΠ͚࣌ͩ/PEFΛεέʔϧͤ͞Α͏  goodoo.tech Service

    - name: app-v1 Service - name: app-v1.1 *OHSFTTͰ੾ସ ϒϧʔάϦʔϯ
  26. Node Pool app-v1 Node Pool app-v1.1 σϓϩΠ͚࣌ͩ/PEFΛεέʔϧͤ͞Α͏  goodoo.tech Service

    - name: app-v1.1 /PEF1PPMΛ࡟আ gcloud container node-pools delete node-pool-app-v1
  27. cluster production.goodoo.tech Service - name: staging DMVTUFS͸؀ڥຖʹΘ͚Δ EFW TUBHJOH QSPEVDUJPO

    Service - name: production production staging staging.goodoo.tech dev.goodoo.tech dev Service - name: dev ˞/BNFTQBDF΋࢖͑Δ͕ࠓճ͸͔ͭΘͳ͍
  28. ΞϓϦͷόʔδϣϯຖʹΘ͚Δ Service - name: app-v2 Service - name: app-v1 NodePool

    goodoo.tech/v1 goodoo.tech/v2 Node Pool app-v2 Node Pool app-v1 ϒϧʔάϦʔϯσϓϩΠ࣌ ͷϚΠφʔόʔδϣϯ͕ ͕͋Δͱ͖΋ಉ༷
  29. w 4FSWFSMFTT"SDIJUFDUVSF - https://speakerdeck.com/naoya/serverless-architecture w "CFNB57ͷಈը഑৴Λࢧ͑ΔαʔόʔαΠυγεςϜ - http://www.slideshare.net/yuichironakazawa2/abematv w XFCσβΠφʔϓϩάϥϚͷͨΊͷ%PDLFS௒ೖ໳

    - https://docs.com/asashiho/4719/web-docker w (,&!"CFNB57 - https://speakerdeck.com/strsk8/gke-at-abematv w Google Container Engine Ͱ৽͍͠ϊʔυʹμ΢ϯλΠϜθϩͰҠߦ͢Δ - http://qiita.com/superbrothers/items/d9766ebaff15d6954d03 ࢀߟจݙ XFC