Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
20180126 M3 TechTalk OpenFaaSお試し
tshohe
January 26, 2018
Technology
0
16
20180126 M3 TechTalk OpenFaaSお試し
tshohe
January 26, 2018
Tweet
Share
More Decks by tshohe
See All by tshohe
tshohe
0
580
tshohe
12
14k
Other Decks in Technology
See All in Technology
clustervr
0
160
clustervr
0
160
conciergeu
0
120
yshr1200
0
170
soracom
0
500
raykataoka
9
7.6k
pg0084
1
120
yaegashi
0
210
karabish
0
170
kenryooo
5
1.4k
myhomenwlab
1
220
gamella
3
1.4k
Featured
See All Featured
addyosmani
494
110k
productmarketing
5
710
chriscoyier
145
20k
62gerente
587
200k
jakevdp
774
200k
nonsquared
81
3.4k
pauljervisheath
196
15k
zenorocha
296
40k
akmur
252
19k
mza
80
4.1k
garrettdimon
287
110k
philhawksworth
192
8.8k
Transcript
OpenFaaS Λࢼͯ͠Έͨ Shohei Takahashi
Who am I? • ߴڮ উฏʢ͔ͨ͠ ͠ΐ͏͍ʣ • 2017/11݄ೖࣾ •
ΠϯϑϥνʔϜॴଐͷSREͱͯ͠ಇ͍ͯ·͢ɻ • ٕज़ɿJava (Spring Boot), Python (Django), PostgreSQLɺ Elastic StackʢElasticsearch, Logstash, Kibanaʣ • झຯɿRaspberry Pi ༡ͼ
͜Ε·Ͱ • ϞϊϦγοΫͳΞϓϦ͔͠ॻ͍ͯͳ͍… • ӡ༻͢͠͞ͱ͔ಛʹҙࣝͯ͠ͳ͍… • ͳΜ͔ͦΕͬΆ͍͜ͱ͍ͨ͠
ڥ • ίʔυ͚ͩॻ͚͋ͱ͍͍ײ͡Ͱಈ͍ͯ͘ΕΔ • मਖ਼͕༰қɺଈ࠲ʹөՄೳ • ΠϯϑϥΛ͋·Γҙࣝ͠ͳͯ͘ྑ͍ • ӡ༻ଆཧָ͕ •
ͱ͔ʁ
OpenFaaS • ίϯςφܕαʔόϨεϑϨʔϜϫʔΫ • Docker/Swarm/Kubernetes⎈্ͰFaaSڥΛߏஙͰ͖ Δͭ • MITϥΠηϯε • ΫϥυαʔϏεͱҟͳΓॾʑͷ੍ݶͳ͠
• Auto-Sacle Մೳ
ಋೖ • 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
http://[kubernetes host]:31112/ui/
ྲྀΕ 1. function هࡌ 2. function Λ Docker image ͱͯ͠Ϗϧυ
3. Docker Registry ʹ push 4. function Λ deploy
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
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))
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
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}
• 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͢Ε͙ͤ͢Δ
function ࣮ߦ࣌ؒՄࢹԽ • Grafanaʹ༗ࢤ͕࡞ͨ͠μογϡϘʔυ͕͋Δ༷ • ҰॹʹPrometheusೖΔͷͰͦ͜Λσʔλιʔεʹࢦఆ͢Δ͚ͩ • AlertManagerσϑΥϧτͰઃఆ͞Ε͍ͯͨΓ͢Δʢ͔ͨ͠ෛՙ্ঢ࣌ɺίϯςφࣦؕ࣌ʣ
·ͱΊ • ׂΓͱ؆୯ʹࢼָͤͯ͛͠ • Ͳ͏αʔϏεΛߏஙͰ͖Δ͔ະ • ΠϕϯτΛݕ࣮ͯ͠ߦͰ͖Δͷ͔ɺͱ͔ • શମ૾ͷཧେมͦ͏ •
function ຖʹόʔδϣϯཧͱ͔ࠞཚͦ͠͏ • Auto-scaleɺFunction Chain ͱ͔ࢼͯ͠Έ͍ͨ
ͦͷଞ function • StoreͳΔͱ͜Ζʹ୭͔͕࡞͕ͬͨؔஔ͍ͯ͋ͬͨΓ