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

GKEで作る動画サービス

umiyosh
June 28, 2017
1.5k

 GKEで作る動画サービス

市ヶ谷Geek★Night#13 GCPはじめました。
https://ichigayageek.connpass.com/event/57962/
Session1:「GKEで作る動画サービス」

umiyosh

June 28, 2017
Tweet

Transcript

  1. 3

  2. 5

  3. 6

  4. 7

  5. 8

  6. 9

  7. 13

  8. Կނkubernetes͔ʁ • Google͸ίϯςφϕʔεͰ10೥ӡ༻࣮ͯͨ͠੷͕͋Δ • googleͷΠϯϑϥ͸99%ίϯςφͰಈ͔ͯ͠ར༻Ͱ͖ΔΑ͏ʹͨ͠తͳ࿦จ • Large-scale cluster management at

    Google with Borg • Borg, Omega, and Kubernetes - ACM Queue • Googleࣾ಺ʹఏڙ͢ΔΠϯϑϥ͸ίϯςφϕʔεɻσʔληϯλʔͷϓϥΠϚϦʔΩʔΛα ʔό͔ΒΞϓϦέʔγϣϯ΁มԽͤͨ͞ • borg -> omegaΛ࡞ͬͯͨਓ͕ͨͪΦʔϓϯιʔεͱͯ͠࠶࣮૷ͨ͠΋ͷ͕kubernetes • KubernetesΛmanagedͳΫϥ΢υαʔϏεͱͯ͠ఏڙ͍ͯ͠Δͷ͕GKE • Kubernetes ͸GoogleΫϥ΢υઓུͷத֩ͱͷ͜ͱ 23
  9. Կނkubernetes͔ʁ • kubernetes͸αʔόͷڥքΛҙࣝ͠ͳ͍ΞϓϦέʔγϣϯσϓϩΠΛ Մೳʹ͢Δ • Data Center as a Computer

    ͱ͍͏ߟ͕͑ࠜͬ͜ʹ͋Δ • ͜ͷߟ͑͸ϚΠΫϩαʔϏεͱ਌࿨ੑ͕ߴ͍ • ϚΠΫϩαʔϏε୯ҐͰͷϦιʔεͷ૿ڧ/ॖୀ͕ϥΫ • Kubernetes1.6Ͱ͸, 5000node, 150000pods·Ͱͷεέʔϧ͕ Մೳ 24
  10. Design • શͯΛKubernetesͰಈ͔͢ඞཁ͸ͳ͍ɻstateful or stateless ? • statelessͳΞϓϦέʔγϣϯ͸ίϯςφͱ૬ੑ͕ྑ͍ • ͱ͸͍͑statefulsetsΛ࢖ͬͯɺঢ়ଶΛ࣋ͬͨίϯςφΛӡ༻͢Δ͜ͱ΋Ͱ͖

    Δ • ઃܭ࣍ୈͩͱࢥ͍·͢ • AbemaTV͸ঢ়ଶΛ࣋ͭΩϟογϡ΋σʔλϕʔε΋ׂΓ੾ΓͰVMͰӡ༻ͯ͠·͢ • ΋͘͠͸managed ͳσʔλετΞΛ࠾༻͢Δͷ΋ྑ͍Ͱ͢Ͷ 29
  11. 32

  12. Overview: ίϯϙʔωϯτ֓ཁ • ReplicaSet: Pod(ίϯςφΠϝʔδ܈)ͷՔಈʹඞཁͳ৘ใΛදݱ͢ΔϦιʔε • Service: ֎෦/಺෦ͱͲͷΑ͏ʹ௨৴͢Δ͔(Endpoint)Λදݱ͢ΔϦιʔε • NodePool

    : Pod͕Քಇ͢ΔVMΛάϧʔϐϯάԽ͢ΔϦιʔε • Node : Pod͕Քಇ͢ΔVM • Pod : ίϯςφΠϝʔδ܈ • Master : kubernetesͷ༷ʑͳ؅ཧΛதԝूݖతʹ؅ཧ͢ΔVMɻmanagedαʔ ϏεͳͷͰීஈҙࣝ͢Δ͜ͱ͸͋·Γͳ͍ 33
  13. 35

  14. 36

  15. Overview: ίϯϙʔωϯτৄࡉ • master/api: kubernetesΛૢ࡞͢ΔͨΊͷAPIΛఏڙ͢Δ • master/controller-manager: ίϯςφͷঢ়ଶ؅ཧ΍ϊʔυͷ؅ཧͱݴ֤ͬͨछ ؅ཧ࡞ۀΛߦ͏ •

    master/scheduler: ֤ϊʔυʹର͠ίϯςφͷׂΓ౰ͯͳͲΛߦ͏ • master/etcd: ϦιʔεͷӬଓԽ૚ɻ෼ࢄKVS • node/proxy: ίϯςφ΁ͷωοτϫʔΫϧʔςΟϯά͓Αͼෛՙ෼ࢄΛߦ͏ • node/kubelet: ֤ϊʔυ্Ͱͷίϯςφ࡞੒/࡟আ΍ϘϦϡʔϜͷׂΓ౰ͯͳͲΛ ߦ͏ 37
  16. 41

  17. rc manifest apiVersion: v1 kind: ReplicationController metadata: name: nginx spec:

    replicas: 3 selector: app: nginx template: metadata: name: nginx labels: app: nginx env: production spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 45
  18. deployment manifest apiVersion: apps/v1beta1 # for versions before 1.6.0 use

    extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 template: metadata: name: nginx labels: app: nginx env: production spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 46
  19. 48

  20. 52

  21. 55

  22. 56

  23. Network : Service 21:26:26 [0] % kubectl describe svc my-service

    Name: my-service Namespace: default Labels: name=my-service Selector: name=my-service Type: NodePort IP: xx.xx.xxx.xxx Port: http 80/TCP NodePort: http 30001/TCP Endpoints: xx.xx.x.x:80,xx.xx.xx.x:80,xx.xx.x.x:80 Session Affinity: None • Port: αʔϏεVIP্ͷԾ૝Port • NodePort: ϗετຖʹଘࡏ͢ΔNodePortͱPodͷContainerPortΛϚοϐϯά͢ΔPort 57
  24. 58

  25. 59

  26. 60

  27. 61

  28. Tool: minikube • kubernetesͷίϯϙʔωϯτͰՔಇ͍ͯ͠ΔΘ͚Ͱ͸ͳ͍ͷ Ͱɺຊ֨తͳݕূʹ͸࢖Θͳ͍΄͏͕ྑ͍Ͱ͢ • VagrantͷΑ͏ͳҐஔ෇͚ͩͱࢥ͍·͢ 16:03:16 [0] %

    kubectl get pod --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE default nginx-ydej2 1/1 Running 0 58m kube-system kube-addon-manager-minikubevm 1/1 Running 0 1d kube-system kubernetes-dashboard-xj6g7 1/1 Running 0 1d 66
  29. 69

  30. ݟͱ͍ͨ΄͏͕͍͍΍ͭ % kubectl explain pod.spec.nodeSelector FIELD: nodeSelector <map[string]string> DESCRIPTION: NodeSelector

    is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. More info: http://releases.k8s.io/release-1.2/docs/user-guide/node-selection/README.md • → ؆қͳઆ໌ʴkubernetes.io͔kubernetes/ kubernetes/docʹ༠ಋͯ͘͠ΕΔ 73