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

K3sを活用した Cloud Native時代のIoTアプリ

Wenhan Shi
September 08, 2020

K3sを活用した Cloud Native時代のIoTアプリ

物づくりが好きな自宅警備員がK3s+Jetsonで自宅監視カメラを開発した話です。

Wenhan Shi

September 08, 2020
Tweet

More Decks by Wenhan Shi

Other Decks in Technology

Transcript

  1. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 1
    © Copyright 2020 Rancher Labs. All Rights Reserved. 1
    K3sを活⽤した
    Cloud Native時代のIoTアプリ
    物づくりが好きな⾃宅警備員
    8th Sept 2020
    Wenhan Shi
    Support Engineer

    View Slide

  2. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 2
    ⾃⼰紹介
    • 施⽂翰 (シ ブンカン) Wenhan Shi
    • @shi_wenhan
    • 経歴
    • ⽇⽴製作所 - Linux カーネルモジュールの開発・保守サポート
    • Red Hat K.K. - GlusterFS/OpenShift サポート
    • Canonical Japan K.K. - Ubuntu/OpenStack/Kubernetes サポート
    • Rancher Lab Inc, - Rancherファミリー/Kubernetesサポート
    兼 ⾃宅警備員

    View Slide

  3. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 3
    • 家まわりの監視が必要
    • 監視カメラが複数台
    • 各デバイスの⼀括管理
    • APPデプロイが簡単
    • IP Addressで監視可能
    • ⾃動回復
    • 動体検知
    • 動画保存
    • 家庭菜園のイチゴ盗難事件
    • 昼寝中宅急便ピンポン事件
    • ⽣ゴミ散らかされ事件
    背景と開発要件

    View Slide

  4. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 4
    役者は、揃った

    View Slide

  5. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 5
    https://www.nvidia.com/en-us/autonomous-machines/jetson-store/
    Jetson Nanoとは

    View Slide

  6. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 6
    4. Run GPU enabled pod
    5. Get GPU info from pod log
    1. Download Nvidia Jetpack SDK >= v4.2.1
    2. Set the Nvidia runtime as a default
    runtime in Docker
    3. Deploy k3s with Docker engine
    Access Jetson GPU in Kubernetes
    {
    “default-runtime”: “nvidia”,
    “runtimes”: {
    “nvidia”: {
    “path”: “nvidia-container-runtime”,
    “runtimeArgs”: []
    }
    }
    }
    curl -sfL https://get.k3s.io | sh -s - --docker
    apiVersion: v1
    kind: Pod
    metadata:
    name: devicequery
    spec:
    containers:
    - name: nvidia
    image: jitteam/devicequery:latest
    command: [ "./deviceQuery" ]
    ./deviceQuery Starting...
    CUDA Device Query (Runtime API) version (CUDART static linking)
    Detected 1 CUDA Capable device(s)
    Device 0: "NVIDIA Tegra X1"
    CUDA Driver Version / Runtime Version 10.2 / 10.2
    CUDA Capability Major/Minor version number: 5.3
    Total amount of global memory: 3964 MBytes (4156780544 bytes)
    ( 1) Multiprocessors, (128) CUDA Cores/MP: 128 CUDA Cores
    GPU Max Clock rate: 922 MHz (0.92 GHz)

    Result = PASS

    View Slide

  7. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 7
    https://github.com/opendatacam/opendatacam

    View Slide

  8. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 8
    https://k3s.io/
    K3sとは
    Rancher Labsが開発した軽量なKubernetesディストリビューション

    View Slide

  9. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 9
    https://www.cncf.io/certification/software-conformance/
    K3sとは
    • 軽量だがCertified Kubernetes distribution • CNCF Sandbox project

    View Slide

  10. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 10
    K3sの特徴
    1. シングルプロセス
    1. Kubernetes Master, Kubelet, containerd
    2. 必須ではないコードを削除し、リソースを節約
    3. SQLite(default) / MariaDB / PostgreSQL / MySQL / etcd
    4. X86_64, Arm64, Armv7
    5. TLS Certification管理
    6. Helm Chart内蔵
    7. L4/L7レイヤのLB機能内蔵
    8. バイナリ︓50MB程度
    9. Minimum MEM︓ 512 MB/server, 75MB/node
    10. Minimum CPU︓ 1 core

    View Slide

  11. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 11
    アーキテクチャー
    MariaDB
    PostgreSQL
    MySQL
    ETCD
    Canal
    Calico
    https://rancher.com/docs/k3s/latest/en/installation/datastore/
    https://rancher.com/docs/k3s/latest/en/installation/network-options/
    https://rancher.com/docs/k3s/latest/en/advanced/#using-docker-as-the-container-runtime
    Docker
    WebSocket

    View Slide

  12. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 12
    Rancherとは
    Amazon
    EKS
    Azure
    AKS
    Google
    GKE
    Cloud
    Datacenter Dev Branch Edge
    OSSベースツールとサービス
    認証 & セキュリティ
    セルフサービスによるKubernetesクラスタのデプロイと運⽤ & インフラストラクチャ管理
    ポリシー管理
    Pod & network
    security policies
    CIS benchmark
    monitoring
    RBAC
    policies
    Configuration
    enforcement
    Visibility &
    diagnostics
    Centralized
    audit
    Monitoring
    & alerting
    Kubernetes version
    management
    Node pool
    management
    Cluster
    provisioning
    Container
    Storage
    Storage Monitoring analytics App Catalog Service Mesh Side-car Proxy Logging
    コンテナアプリケーション 1 コンテナアプリケーショ 2 コンテナアプリケーション 3
    Windows Linux

    View Slide

  13. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 13
    Rancher - 複数クラスタの⼀元管理

    View Slide

  14. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 14
    Rancher - 多様なクラスター環境を対応

    View Slide

  15. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 15
    Rancher - 3rd partyプラグインの親和性

    View Slide

  16. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 16
    システム構成
    Jetson0
    GPU
    Camera
    Disk
    Jetson1
    GPU
    Camera
    Disk
    Jetson2
    GPU
    Camera
    Disk
    Disk
    http://20.0.0.20:3xxxx
    http://20.0.0.21:3xxxx
    http://20.0.0.22:3xxxx

    View Slide

  17. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 17
    アプリケーション構成
    Jetson Nano Developer Kit
    (JetPack)
    K3s
    OpenCV
    Video Stream
    Flask
    PyImageSearch +
    動体検知時の動画保存
    https://www.pyimagesearch.com/2019/09/02/ope
    ncv-stream-video-to-web-browser-html-page/

    View Slide

  18. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 18
    • 電源は5V4AのACアダプターを使⽤
    • MicroUSBもあるが、最⼤2A
    • CUDAコアをフル稼働のため4Aが必要
    • V2以上のRasberry Pi カメラは使⽤可能
    試作環境
    使えず。。

    View Slide

  19. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 19
    運⽤環境

    View Slide

  20. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 20
    Demo! Demo! Demo!
    • K3sのインストール
    • Rancherシステムに追加
    • Rancher GUIでアプリケーションのデプロイ
    • app image, node port, volume, Privileged container.
    • 監視動作確認
    • 録画ファイル確認
    • k3sのアップグレード
    curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.17.9+k3s1 sh -s - --docker

    View Slide

  21. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 21
    ユースケース
    録画データの低減 危険の事前検知
    複数監視ポイント対応

    View Slide

  22. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 22
    • Jetson Nanoはパワフル
    • USBカメラ、WIFIモジュールがドライバなしですぐ使えた
    • ヒートシンクのおかげでファンなしでもいける(のはず)
    • オンラインのドキュメント、サンプルコードが充実
    • 改善して欲しいところ
    • WIFIモジュールがOnboardになって欲しい
    • ファン取り付けのネジ⽳が難あり
    感想 - ハードウェア

    View Slide

  23. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 23
    • K3s
    • 環境構築が早い、k8s runtime的な存在
    • 最初からArm対応のためSBCに最適
    • リソース消費が少なく、他のアプリに回せる
    • Certificated K8sのため、学習コストがほぼない
    • Rancher
    • 複数クラスタを⼀元管理できたので楽
    • デプロイ、URLアクセスも全部GUIでできたので楽
    • 新しいサービスのデプロイが簡単
    感想 - ソフトウェア

    View Slide

  24. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 24
    • 動体検知された時の通知機能
    • 本格的に屋外に利⽤するときの温湿度・⾬・⾵対策
    • の実装
    • CNCF Sandbox project
    • Armのサポートする予定(v1.2)
    • ディスク使⽤量・Heathyのモニタリング
    • Volumeの⾃動バックアップ(S3/NFS)
    Todo

    View Slide

  25. © Copyright 2020 Rancher Labs. All Rights Reserved. Confidential 25 25
    Thank you

    View Slide