Weitere ähnliche Inhalte Ähnlich wie with NATS with Kubernetesの世界へ (20) with NATS with Kubernetesの世界へ3. Agenda
3
2
1 About NATS
NATS, NATS Streaming, Deploy, Monitoring, Logging, Benchmark
NATS with Kubernetes
Cluster, Deploy (NATS Operator)
OpenFaas with NATS with Kubernetes
Architecture, Deploy
8. 順位 プロダクト名 登場回数
1 Cloud Storage 30
2 Compute Engine 24
3 BigQuery 23
4 App Engine 21
5 Cloud Dataflow 18
6 Cloud Load Balancing 15
7 Kubernetes Engine 13
7 Cloud PubSub 13
9 Cloud Bigtable 12
9 Cloud SQL 12
GCPサンプルソリューション登場プロダクト Top 10
メッセージングシステムを
必要とするソリューションは
多い!!
10. Availability
Cluster
Security
TLS / User-Token
based Authentication
/ Authorization
Go言語で実装されたオープンソースのメッセージングシステム
(ソフトウェア / ハードウェアを問わず、分散したシステム間のメッセージのやり取り(送受信)をサポート)
NATS
Neural Autonomic Transport System
1 Performance and
Scalability
1,800万メッセージ/秒
2
Simplicity
Single binary / Text-based
protocol / No external
dependencies
3
4
DNA
12. NATS Streaming
データストリーミングシステム powerd by NATS
> Delivery: At-least-once
クライアントが接続した際に、過去のメッセージも受信
可能。
> Storage: Memory, File or Database
ストレージ上にメッセージを保存することで実装。
> Store Limits設定可能
Subject毎にメッセージの保存期間を設定可能。
13. Monitoring
Endpoint for metrics nats-top Prometheus
Grafana
NATS
Server
NATS
Server
Prometheus
NATS
Prometheus
Exporter
NATS
Prometheus
Exporter
nats-top is a top like tool
for monitoring NATS
servers.
http://localhost:8222/vars
http://localhost:8222/connz
http://localhost:8222/subsz
http://localhost:8222/routez
14. Logging
<実行コマンド>
$ gnatsd -s udp://localhost:514
<実行コマンド>
$ gnatsd -l nats.log
ログファイル出力 Syslog
<その他オプション>
-l, --log FILE File to redirect log output.
-T, --logtime Timestamp log entries (default is true).
-s, --syslog Enable syslog as log method.
-r, --remote_syslog Syslog server address.
-D, --debug Enable debugging output.
-V, --trace Trace the raw protocol.
-DV Debug and Trace.
15. <実行環境>
CPU: Intel Xeon CPU E5-2643 3.30GHz
Memory: 32GB
<ベンチマークツール(nats-bench)インストール>
$ go get github.com/nats-io/go-nats
$ go install $GOPATH/src/github.com/nats-io/go-nats/examples/nats-bench.go
<NATS実行>
$ gnatsd
<実行コマンド: オプション確認>
$ nats-bench -h
-np NUM_PUBLISHERS
-ns NUM_SUBSCRIBERS
-n NUM_MSGS
-ms MESSAGE_SIZE <subject>
ベンチマークとチューニング
<実行コマンド N:Mスループットテスト>
$ nats-bench -np 5 -ns 5 -n 10000000 -ms 16 foo
...省略...
NATS Pub/Sub stats: 6,666,260 msgs/sec 101.72 MB/sec
...省略...
チューニングのナレッジをお
持ちの方いらっしゃいます
か?
17. Let’s Deploy!
<前提条件>
・Go 1.5+ and set $GOPATH
<実行コマンド>
$ go get github.com/nats-io/gnatsd
$ gnatsd
<前提条件>
・Dockerインストール
<実行コマンド>
$ docker run -p 4222:4222 nats
ソースインストール & 実行 Dockerコンテナ実行
Client
NATS
NATS NATS
4222
Management
HTTP/
HTTPS
8222
route:
6222
18. $ telnet localhost 4222
Trying ::1...
Connected to localhost.
Escape character is '^]'.
INFO
{"server_id":"34wyPXXqogfLVYw2fMvMpc","vers
ion":"1.1.1","git_commit":"","go":"go1.10.2","host":"
0.0.0.0","port":4222,"auth_required":false,"tls_re
quired":false,"tls_verify":false,"max_payload":104
8576}
pub foo.bar 5
hello
+OK
Let’s Pub/Sub!
(Human NATS Client: Telnet)
Subscriber実行 Publisher実行
$ telnet localhost 4222
Trying ::1...
Connected to localhost.
Escape character is '^]'.
INFO
{"server_id":"34wyPXXqogfLVYw2fMvMpc","vers
ion":"1.1.1","git_commit":"","go":"go1.10.2","host":"
0.0.0.0","port":4222,"auth_required":false,"tls_re
quired":false,"tls_verify":false,"max_payload":104
8576}
sub foo.* 90
+OK
MSG foo.bar 90 5
hello
1
2
3
4
5
22. $ echo '
apiVersion: "nats.io/v1alpha2"
kind: "NatsCluster"
metadata:
name: "example-nats-cluster"
spec:
size: 3
version: "1.1.0"
' | kubectl -n nats-io apply -f -
Let’s Deploy (NATS Operator)!
<手順>
$ kubectl apply -f
https://raw.githubusercontent.com/nats-io/nats
-operator/master/example/deployment.yaml
$ kubectl get pod -n nats-io -o wide
$ kubectl get service -n nats-io
$ kubectl get crd -n nats-io
NAME AGE
natsclusters.nats.io 1h
1
3
2
27. <前提条件>
・Kubernetes 1.8 or 1.9 cluster running on Linux hosts.
・Install Helm.
<実行コマンド>
$ git clone https://github.com/openfaas/faas-netes.git
$ cd faas-netes/chart
$ kubectl create ns openfaas
$ kubectl create ns openfaas-fn
$ helm upgrade --install openfaas openfaas/
--namespace openfaas --set functionNamespace=openfaas-fn
Let’s Deploy OpenFaaS!
28. <実行コマンド>
$ curl -sL https://cli.openfaas.com
$ git clone https://github.com/openfaas/faas-cli
$ cd faas-cli
$ faas-cli deploy -f stack.yml --gateway http://127.0.0.1:31112
$ faas-cli list --gateway http://127.0.0.1:31112
Function Invocations Replicas
nodejs-echo 0 1
<同期実行コマンド>
$ curl http://127.0.0.1:31112/function/nodejs-echo -d “hello”
{"nodeVersion":"v8.9.1","input":"“hello”"}
<非同期実行コマンド>
$ curl http://127.0.0.1:31112/async-function/nodejs-echo -d “hello”
Let’s Deploy Samples!
30. 1. Youtube - NATS Intro
https://www.youtube.com/watch?v=Y9bDY_oE80w
2. Youtube - NATS Deep Dive
https://www.youtube.com/watch?v=MAKYz8oPRyw
3. THE LINUX FOUNDATION - CNCFがNATSをホストへ
https://www.linuxfoundation.jp/blog/cncf-to-host-nats/
4. cloud.google.com - GCP Offical Icons and Sample Solutions
https://docs.google.com/presentation/d/1vjm5YdmOH5LrubFhHf1vlqW2O9Z2UqdWA8biN3e8K5U/edit?hl=ja#slide=id.g1a
96c6729e_19_0
5. GitHub - Cloud Native Landscape and Trail map
https://github.com/cncf/landscape
6. NATS Cloud - Introducing NATS Cloud
https://www.nats.cloud/
7. GitHub - NATS - The Cloud Native Messaging System
https://github.com/nats-io
8. Docker Hub - NATS
https://hub.docker.com/_/nats/
9. OpenFaaS - Deployment guide for Kubernetes
https://docs.openfaas.com/deployment/kubernetes/
10. GitHub - The Raft Consensus Algorithm
https://raft.github.io/
参考サイト