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

20180126 M3 TechTalk OpenFaaSお試し

05d61346e75286cf44c54f4d3099db24?s=47 tshohe
January 26, 2018

20180126 M3 TechTalk OpenFaaSお試し

05d61346e75286cf44c54f4d3099db24?s=128

tshohe

January 26, 2018
Tweet

Transcript

  1. OpenFaaS Λࢼͯ͠Έͨ Shohei Takahashi

  2. Who am I? • ߴڮ উฏʢ͔ͨ͸͠ ͠ΐ͏΁͍ʣ • 2017/11݄ೖࣾ •

    ΠϯϑϥνʔϜॴଐͷSREͱͯ͠ಇ͍ͯ·͢ɻ • ٕज़ɿJava (Spring Boot), Python (Django), PostgreSQLɺ Elastic StackʢElasticsearch, Logstash, Kibanaʣ • झຯɿRaspberry Pi ༡ͼ
  3. ͜Ε·Ͱ • ϞϊϦγοΫͳΞϓϦ͔͠ॻ͍ͯͳ͍… • ӡ༻͠΍͢͞ͱ͔΋ಛʹҙࣝͯ͠ͳ͍… • ͳΜ͔ͦΕͬΆ͍͜ͱ͍ͨ͠

  4. ؀ڥ • ίʔυ͚ͩॻ͚͹͋ͱ͸͍͍ײ͡Ͱಈ͍ͯ͘ΕΔ • मਖ਼͕༰қɺଈ࠲ʹ൓өՄೳ • ΠϯϑϥΛ͋·Γҙࣝ͠ͳͯ͘΋ྑ͍ • ӡ༻ଆ͸؅ཧָ͕ •

    ͱ͔ʁ
  5. OpenFaaS • ίϯςφܕαʔόϨεϑϨʔϜϫʔΫ • Docker/Swarm/Kubernetes⎈্ͰFaaS؀ڥΛߏஙͰ͖ Δ΍ͭ • MITϥΠηϯε • Ϋϥ΢υαʔϏεͱҟͳΓॾʑͷ੍ݶͳ͠

    • Auto-Sacle Մೳ
  6. ಋೖ • KubernetesΛόοΫΤϯυͱͯ͠࢖͏ͨΊͷϓϥάΠϯfaas-netes͕͋Δ • helmͰ΋ೖΔΒ͍͠ʢෆ۩߹͕͋ͬͨͷͰkubectlͰʣ • OpenFaaS on Kubernetes on

    Rancher $ curl -LO https://github.com/openfaas/faas- netes/archive/master.zip $ unzip master.zip $ cd faas-netes-master $ kubectl apply -f ./namespaces.yml $ kubectl apply -f ./yaml
  7. http://[kubernetes host]:31112/ui/

  8. ྲྀΕ 1. function هࡌ 2. function Λ Docker image ͱͯ͠Ϗϧυ

    3. Docker Registry ʹ push 4. function Λ deploy
  9. function هࡌ • GUIͰ΋͍͍͚Ͳɺcliπʔϧ͕͋ΔͷͰͦΕΛ࢖͏ʢbrewͰೖΔʣ • ্هίϚϯυͰԼهͷΑ͏ͳ਽ܗ͕࡞੒͞ΕΔ ʢݴޠ͸PythonΛબ୒ɺ͍Ζ͍Ζબ΂·͢ʣ • template ……

    ֤ݴޠ༻ͷDockerfile౳ʢgo, node.js, ruby, python, C#ʣ • ؔ਺໊σΟϨΫτϦ • handler.py ……. ࣮ࡍͷؔ਺Λهࡌ͢Δɻ • requirement.txt …… ࢖͍͍ͨύοέʔδ͕͋Ε͹ • ؔ਺໊.yml …… gateway, language, docker image name౳ઃఆ $ faas-cli new --lang python test-function $ ls template test-function test-function.yml
  10. function هࡌ • stdinΛड͚औͬͯstdoutΛ݁Ռͱͯ͠ฦ͢functionΛهࡌ • ͻͱ·ͣ଍͠ࢉؔ਺Λ࡞੒ $ vi test-function/handler.py import

    json def handle(req): json_req = json.loads(req) answer = int(json_req["a"]) + int(json_req["b"]) result = {"answer": answer} print(json.dumps(result))
  11. function Ϗϧυ • [Local Docker Registry]:5000/tshohe/test-function: 0.0.1 ͱͯ͠Ϗϧυ • ϩʔΧϧͰςετͱ͔Ͱ͖Δ

    • ϕʔεͷpython 2.7-alpine͕Ͱ͔͍ͷͰɺ݁ߏͰ͔͍ $ faas-cli build -f ./test-function.yml $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE [Local Docker Registry]:5000/tshohe/test-function 0.0.1 ae45b01bb0bb 34 seconds ago 81.1MB
  12. function deploy & ࣮ߦ • ଍͠ࢉ͕࣮ߦͰ͖ͯΔ • -> API Gateway

    <-> Watchdog <-> Function $ faas-cli push -f ./test-function.yml $ faas-cli deploy -f ./test-function.yml $ curl [kubernetes host]:31112/function/test-function -d '{"a":1,"b": 2}' {"answer": 3}
  13. • tagΛ0.0.2ʹͯ͠build & push & deploy • ൓өʂ function मਖ਼

    - answer = int(json_req["a"]) + int(json_req["b"]) + answer = int(json_req["a"]) * int(json_req[“b”]) $ curl [kubernetes host]:31112/function/test-function -d '{"a":1,"b":2}' {"answer": 2} • function Λमਖ਼ • tagΛࢦఆ͠௚ͯ͠deploy͢Ε͹͙͢໭ͤΔ
  14. function ࣮ߦ࣌ؒՄࢹԽ • Grafanaʹ༗ࢤ͕࡞੒ͨ͠μογϡϘʔυ͕͋Δ໛༷ • ҰॹʹPrometheus΋ೖΔͷͰͦ͜Λσʔλιʔεʹࢦఆ͢Δ͚ͩ • AlertManager΋σϑΥϧτͰઃఆ͞Ε͍ͯͨΓ͢Δʢ͔ͨ͠ෛՙ্ঢ࣌ɺίϯςφࣦؕ࣌ʣ

  15. ·ͱΊ • ׂΓͱ؆୯ʹࢼָͤͯ͛͠ • Ͳ͏αʔϏεΛߏஙͰ͖Δ͔͸ະ஌਺ • ΠϕϯτΛݕ஌࣮ͯ͠ߦͰ͖Δͷ͔ɺͱ͔ • શମ૾ͷ؅ཧେมͦ͏ •

    function ຖʹόʔδϣϯ؅ཧͱ͔ࠞཚͦ͠͏ • Auto-scaleɺFunction Chain ͱ͔ࢼͯ͠Έ͍ͨ
  16. ͦͷଞ function • StoreͳΔͱ͜Ζʹ୭͔͕࡞ͬͨؔ਺͕ஔ͍ͯ͋ͬͨΓ