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

20180126 M3 TechTalk OpenFaaSお試し

tshohe
January 26, 2018

20180126 M3 TechTalk OpenFaaSお試し

tshohe

January 26, 2018
Tweet

More Decks by tshohe

Other Decks in Technology

Transcript

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

    ΠϯϑϥνʔϜॴଐͷSREͱͯ͠ಇ͍ͯ·͢ɻ • ٕज़ɿJava (Spring Boot), Python (Django), PostgreSQLɺ Elastic StackʢElasticsearch, Logstash, Kibanaʣ • झຯɿRaspberry Pi ༡ͼ
  2. ಋೖ • 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
  3. ྲྀΕ 1. function هࡌ 2. function Λ Docker image ͱͯ͠Ϗϧυ

    3. Docker Registry ʹ push 4. function Λ deploy
  4. 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
  5. 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))
  6. 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
  7. 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}
  8. • 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͢Ε͹͙͢໭ͤΔ