JSUG20171027-spfingboot-k8s-ocp

321 views

Published on

Spring Boot on Kubernetes / OpenShift

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
321
On SlideShare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

JSUG20171027-spfingboot-k8s-ocp

  1. 1. JSUG勉強会 2017年その8 Spring Boot on Kubernetes/OpenShift 2017年 10月 27日 レッドハット株式会社 テクニカルセールス本部 シニアソリューションアーキテクト 須江 信洋 (nosue@redhat.com / @nobusue)
  2. 2. Agenda • マイクロサービスとSpringとコンテナ • Kubernetesで動かすミニマルなSpring Boot Microservices または Kubernetes概観 (by 林さん) • Fabric8 Maven Plugin • Spring Cloud Kubernetes 2
  3. 3. 自己紹介 • 須江 信洋(すえ のぶひろ) – Mail: nosue@redhat.com – Twitter: @nobusue • 約14年JavaEE関連に携わる(1999〜2013) • Enterprise Mobile製品担当(2012〜2013) • IoTサービス関連ベンチャー 開発から運用まで (2014〜2017) – ストリーミングデータ処理 – マイクロサービス化 – コンテナプラットフォーム構築/運用 3
  4. 4. マイクロサービスとコンテナ 4
  5. 5. サービスが小さく、自律 的であるため、素早く開 発してデリバリーできる サービスが小さいため、 デリバリーの自動化やモ ニタリングが容易 細かい粒度でスケーラビ リティを制御でき、リソー スの利用を最適化しやす い SCALABILITY よく聞くマイクロサービスのメリット FAST TIME TO MARKET EFFICIENCY 5
  6. 6. 例えばスケーラビリティ モノリシックなシステム Microservices アプリケーション単位でしか スケールアウトできない サービス単位で細かくリソース 調整可能 6
  7. 7. マイクロサービスの課題 MyService Resilience Discovery Load Balancing Scaling / Elasticity Logging Monitoring Build, Deployment Pipeline Tracing Invocation Messaging / IPC API Authentication 7
  8. 8. マイクロサービスの課題 l 構築 Ø サービスの境界 / 粒度 Ø ビルド / デプロイの効率化 Ø サービス間連携 (サービスディスカバリ、オーケストレーション、コレオグラフィー) Ø テスト (サービス単位 / エンドツーエンド) Ø 自律的な回復 l 運用 Ø サービスの健全性の管理 / 監視 Ø サービス障害対応 (ログ集中管理、トレーサビリティ ) Ø サービス間の依存関係の管理 (バージョニング、データマイグレーション) Ø パフォーマンス管理 / リソース管理 Ø API管理 (特に外部公開用) l セキュリティ Ø 分散環境での認証 / 認可 Ø 暗号化 Ø 監査 8
  9. 9. Spring Boot + Spring Cloud 9 https://spring.io/ 12 factor app原則に基づいた シンプル/コンパクトなサービスを JVMベースで実装 マイクロサービスの課題を 解決するための 抽象化レイヤーを提供
  10. 10. サービスインスタンス増 => コンテナ+オーケストレーションが有効 10 Proxy (Nginx) LB Internet Proxy (Nginx) 認証 Svc 認証 Svc Query API Cache Svc Mongo Svc Cassandra Svc Mongo Cassandra Query API Cache Svc Mongo Svc Cassandra Svc Mongo Mongo Cassandra Cassandra
  11. 11. 11 コンテナのメリット 1. (アプリケーション + 環境) をまるごとパッケージング できる 2. ポータビリティが高く、どこでも実行できる 3. 仕組みがシンプルで、リソース利用効率が良い
  12. 12. コンテナのポータビリティ 12 LAPTOP Container Application OS dependencies Guest VM RHEL BARE METAL Container Application OS dependencies RHEL VIRTUALIZATION Container Application OS dependencies Virtual Machine RHEL PRIVATE CLOUD Container Application OS dependencies Virtual Machine RHEL PUBLIC CLOUD Container Application OS dependencies Virtual Machine RHEL Linuxカーネルの仕組みを利用している = Linuxが動くあらゆる環境での可搬性
  13. 13. Kubernetesで動かすミニマルな Spring Boot Microservices または Kubernetes概観 (by 林さん) 13
  14. 14. Fabric8 Maven Plugin 14
  15. 15. Spring Boot -> Kubernetesの課題 • Spring Bootアプリケーションのコンテナ化 – Dockerfile ? – EXPOSE / VOLUME ? • Kubernetesへのデプロイ – YAML ? – Pod / Service ? – 環境構築 ? – アプリケーションへのアクセス ? 15
  16. 16. Fabric8 Maven Plugin • Spring Bootアプリケーションのコンテナ化を簡単に!! – Dockerfile 不要 – Mavenによるビルドワークフローへの組み込み • Kubernetes/OpenShiftへのデプロイを簡単に!! – YAML 不要 (必要十分なデフォルトを補う) • 必要に応じてYAMLのテンプレートを適用することも可能 • Docker Composeの定義ファイルを利用することも可能 – Pod / Service を自動的に定義 16 https://maven.fabric8.io/
  17. 17. 環境構築: minikube • minikubeとは? – all in one構成で実行可能なKubernetes – 全コンポーネントをコンテナベースで実行 • minikube実行方法 – Running Kubernetes Locally via Minikube • https://kubernetes.io/docs/getting-started-guides/minikube/ – Install Minikube • https://kubernetes.io/docs/tasks/tools/install-minikube/ 17
  18. 18. minikubeインストール(Macの場合) • 前提 – dockerおよびdocker-machineがインストールされていること – (オプション)docker-machine-xhyve-driver • Kubernetes CLI (kubectl) インストール – Kubernetesの操作に必要 – $ brew install kubectl • minikube インストール – $ brew cask Install minikube 18
  19. 19. minikube実行 • 起動 – $ minikube start # VirtualBox – $ minikube start --vm-driver xhyve # xhyve • 仮想マシンのIP確認 – $ minikube ip • ダッシュボード表示 – $ minikube dashboard • 停止 – $ minikube stop 19 ※ うまく起動しないときは $ minikube delete でVMを削除してからstart
  20. 20. minikube上でのアプリケーション実行テスト • hello-minikube実行 – $ kubectl run hello-minikube -- image=gcr.io/google_containers/echoserver:1.4 --port=8080 • サービス公開(NodePort) – $ kubectl expose deployment hello-minikube --type=NodePort • Pod起動確認 – $ kubectl get pod • アプリケーション実行 – $ minikube service hello-minikube 20
  21. 21. SpringBoot Appをminikubeにデプロイする(1) • minikube起動 – $ minikube start --vm-driver xhyve • minikube VM上のdockerを使う設定 – $ eval $(minikube docker-env) • これをやっておかないとイメージが見つからずデプロイが失敗 する 21
  22. 22. SpringBoot Appをminikubeにデプロイする(2) • Sample: Zero-Config – https://github.com/fabric8io/fabric8-maven- plugin/tree/master/samples/zero-config – fabric8-maven-pluginのバージョンが間違っているのでpom.xmlの 修正が必要(最新は3.5.31) • https://mvnrepository.com/artifact/io.fabric8/fabric8-maven- plugin • 既存のプロジェクトに適用する場合は、以下を実行する – $ mvn io.fabric8:fabric8-maven-plugin:3.5.31:setup – pom.xmlにfabric8-maven-pluginが追加される 22
  23. 23. SpringBoot Appをminikubeにデプロイする(3) • ビルド – $ mvn package fabric8:build – $ mvn fabric8:resource # k8s用リソース生成 • フォアグラウンド実行 – $ mvn fabric8:run • デプロイ – $ mvn fabric8:deploy 23 ※標準入出力を使うのでタイムアウト等で失敗することがあるが、 再実行すればたいていうまくいく
  24. 24. SpringBoot Appをminikubeにデプロイする(4) • アプリケーションへのアクセス – PodやServiceには、デフォルトではKubernetesクラスタ内からしか アクセスできないIPアドレスがアサインされている(仮想ネットワー クが構成されているため) • アクセス可能にするための方法は以下 1. ポートフォワードでPodに直接接続する 2. Ingress Routerを有効にする (minikubeではやや面倒) 3. exposecontrollerを使う • https://github.com/fabric8io/exposecontroller 24
  25. 25. ポートフォワード • ポートフォワードでPodに直接接続できる – $ kubectl port-forward <POD名> 8080:8080 – $ open http://localhost:8080/ • サービスへのフォワードは未サポート 25
  26. 26. exposecontroller • 環境構成に応じてサービスをexposeしてくれる便利ツール • exposecontrollerのデプロイ – $ kubectl create -f http://central.maven.org/maven2/io/fabric8/devops/apps/exposec ontroller/2.2.268/exposecontroller-2.2.268-kubernetes.yml • サービス公開 – $ kubectl label svc SVC名 expose=true • アクセス – $ minikube service SVC名 26
  27. 27. What is OpenShift? 27 ü エンタープライズコンテナプラットフォーム ü [Docker+Kubernetes+PaaS機能] x DevOps CONTAINER Image OS RUNTIME APP RHEL Java script Java Perl Ruby .NET Python PHP CC++ SQL ビルド デプロイ・オーケストレーション 利用ソースコード Node Node Node
  28. 28. 環境構築: minishift • minishiftとは? – all in one構成で実行可能なOpenShift – 全コンポーネントをコンテナベースで実行 • minishift実行方法 – Getting Started with Minishift • https://docs.openshift.org/latest/minishift/getting- started/index.html 28
  29. 29. minishiftインストール(Macの場合) • 前提 – dockerおよびdocker-machineがインストールされていること – (オプション)docker-machine-xhyve-driver • OpenShift CLI (oc) インストール – OpenShiftの操作に必要 – $ brew install openshift-cli • minishift インストール – $ brew cask Install minishift 29
  30. 30. minishift実行 • 起動 – $ minishift start # VirtualBox – $ minishift start --vm-driver xhyve # xhyve • 仮想マシンのIP確認 – $ minishift ip • 管理コンソール表示 – $ minishift console • 停止 – $ minishift stop 30
  31. 31. SpringBoot Appをminishiftにデプロイする(1) • minishift起動 – $ minishift start --vm-driver xhyve • minishift VM上のdockerを使う設定 – $ eval $(minishift docker-env) • これをやっておかないとイメージが見つからずデプロイが失敗 する 31
  32. 32. SpringBoot Appをminishiftにデプロイする(2) • ビルド – $ mvn package fabric8:build # デプロイ先(OpenShift)を自動判定 – $ mvn fabric8:resource • フォアグラウンド実行 – $ mvn fabric8:run • デプロイ – $ mvn fabric8:deploy 32
  33. 33. SpringBoot Appをminishiftにデプロイする(3) • アプリケーションへのアクセス – OpenShiftにはRouter(LB)が内蔵されており、クラスタ外へのサー ビス公開が簡単に実行できる – minishift環境では、nip.ioを利用したDNS名が割り振られる • ホスト名にIPを含み、メンテナンスが必要ない – fabric8-maven-pluginを利用した場合、デフォルトではサービスが 自動的に公開されるため、特に操作は必要ない 33
  34. 34. minishiftの管理コンソールから確認 34 ここをクリック!
  35. 35. Fabric8 Maven PluginのGoals • Build Goals – https://maven.fabric8.io/#goals-overview-build – ビルドやパッケージングに関するGoals • Development Goals – https://maven.fabric8.io/#goals-overview-develop – デプロイや実行に関するGoals • Infrastructure Goals – https://maven.fabric8.io/#goals-overview-setup – インストールやクラスタ起動停止に関するGoals 35
  36. 36. Spring Cloud Kubernetes 36
  37. 37. Java Microservices Platform: 2014 Config Server NETFLIX Ribbon
  38. 38. コンポーネントの役割 Eureka: クライアントがサービスのロケーション をルックアップするためのサービスレジストリ Config Server Zuul: Javaベースのスマートプロキシ Ribbon: クライアントサイドロードバランサー Hystrix: サーキットブレーカー Config Server: コンフィグレーションの外部化 Zipkin: 分散トレース
  39. 39. Better Spring Boot Microservices Platform: 2016 Config Server NETFLIX Ribbon
  40. 40. https://github.com/spring-cloud-incubator/spring-cloud-kubernetes
  41. 41. • Service Discovery Spring Discovery Client using Kubernetes Service Discovery ▪ ConfigMap Property Source How to use Kubernetes ConfigMap as Spring Property source ▪ Ribbon Service Discovery Using Netflix Ribbon with Kubernetes Service Discovery ▪ Zipkin Service Discovery Using Zipkin with Kubernetes for distributed tracing ▪ Archaius Config Management Using Netflix Archaius with Kubernetes Config Map Spring Cloud Kubernetes
  42. 42. プロジェクトへの追加方法 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-kubernetes-discovery</artifactId> <version>0.2.0.RELEASE</version> </dependency> Spring Cloud Kubernetes Discovery Spring Cloud Kubernetes Config Spring Cloud Kubernetes ArchaiusSpring Cloud Kubernetes Netflix Spring Cloud Kubernetes Zipkin https://github.com/spring-cloud-incubator/spring-cloud-kubernetes <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-kubernetes-config</artifactId> <version>0.2.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-kubernetes-archaius</artifactId> <version>0.2.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-kubernetes-netflix</artifactId> <version>0.2.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-kubernetes-config</artifactId> <version>0.2.0.RELEASE</version> </dependency>
  43. 43. Spring Applicationのマイグレーション例 Spring Cloud Breweryを移行するサンプル Docs & Sources • Iteration 1: Lift and Shift (コード修正なし)、Mavenビルド追加 • Iteration 2: 不要なSpring Boot/Cloudコンポーネントを削除 – Config Server -> ConfigMap – Eureka -> Kubernetes Services • Iteration 3: – RabbitMQ -> Artemis – Zipkin -> OpenTracing+Jaeger – Ribbon -> Kubernetes Services • Iteration 4: Service Mesh適用
  44. 44. RUNTIMES (Container images and Maven Artifacts) JAVA EE (JBoss EAP) MICROPROFIL E (WildFly Swarm) OPENSHIFT SERVICES REACTIVE (vert.x) NODE.JS APACHE TOMCAT TESTED FRAMEWORKS (Maven Artifacts) SPRING BOOT / CLOUD NETFLIX OSS Ribbon OpenShift.io (Developer SaaS) Generators IDE etc. Management APM Metrics Service Discovery Config. Logging Health Check Load Balancing CI/CDSSOMessaging IMDG API Mgmt NETFLIX OSS Hysterix ... Red Hat OpenShift Application Runtimes
  45. 45. Better Spring Boot Microservices Platform: 2017 Config Server NETFLIX Ribbon
  46. 46. Even Better Microservices Platform: 2018 Config Server NETFLIX Ribbon Istio
  47. 47. マイクロサービス課題への対応: サービスメッシュ l マイクロサービス間の連携を透過的に扱うためのレイヤーを提供 Ø HTTPやgRPCなどの低レイヤーの通信を隠蔽(タイムアウト、リトライ等) Ø サービスディスカバリとルーティング、トラフィック制御 Ø サービス障害の影響を最小化 (例: circuit breaker) Ø サービス間認証/認可、暗号化 Ø サービス全体のモニタリングとレポーティング l Kubernetes(コンテナ基盤)上の新たな「ミドルウェア」 Ø Istio (https://istio.io/) Ø linkerd (https://linkerd.io/) 4 8
  48. 48. Istio / linkerdに至る歴史 4 9 Finangle linkerd Envoy Istio 2010〜 by Twitter Library for JVM 2016〜 by Buoyant =>CNCF Service Mesh (JVM based Standalone Proxy) 2016〜 by Lyft Standalone Proxy (C++ based) 2017〜 by Lyft/Google/IBM Service Mesh (Envoy core) https://linkerd.io/ https://lyft.github.io/envoy/ https://istio.io/ https://twitter.github.io/finagle/
  49. 49. Istioの適用イメージ on Kubernetes 5 0 マイクロサービスで構成された アプリケーション マイクロサービスをサービスメッシュで 連携したアプリケーション(Istioの例) source: https://istio.io/docs/samples/bookinfo.html
  50. 50. CNCF(Cloud Native Computing Foundation) 51 https://www.cncf.io/
  51. 51. 詳しくはSpring Fest 2017にて!! Kamesh Sampath • Creator of vertx-maven-plugin • Contributor fabric8 platform kamesh_sampath ksampath@redhat.com kameshsampath
  52. 52. 参考情報 • Spring Cloudアプリケーションの開発にDockerを活用し、 Kubernetes上にデプロイするまで – https://speakerdeck.com/muraken720/spring- cloudapurikesiyonfalsekai-fa-nidockerwohuo-yong-si- kubernetesshang-nidepuroisurumade • Spring Cloud Netflixを使おう – https://www.slideshare.net/makingx/spring-cloud-netflix 53
  53. 53. Thank you
  54. 54. 補足: Envoy(Istio)によるマイクロサービスパターン l Kubernetes(OpenShift)の"Sidecar Proxy"を利用したマイクロサー ビスデザインパターンの紹介 Ø "Microservices Patterns with Envoy Sidecar Proxy, Part I: Circuit Breaking" https://blog.openshift.com/microservices-patterns-envoy-part-i/ Ø "Microservices Patterns with Envoy Proxy, Part II: Timeouts and Retries" https://blog.openshift.com/microservices-patterns-envoy-proxy- part-ii-timeouts-retries/ Ø "Microservices Patterns With Envoy Proxy, Part III: Distributed Tracing" https://blog.openshift.com/microservices-patterns-envoy-proxy- part-iii/ 5 5
  55. 55. 補足: SpringBootマイクロサービス on OpenShiftの リファレンスアーキテクチャ l OpenShift(Kubernetes)上でSpringBootベースのマイクロサービスを実 装するためのリファレンスアーキテクチャとサンプルコードを提供 Ø Netflix OSSを中心とした、比較的な保守的なテクノロジスタックを採 用しており、今すぐ使いたいという用途には最適 Ø 最新動向については比較検討のための情報のみ提供 l "Spring Boot Microservices on Red Hat OpenShift Container Platform 3" Ø https://access.redhat.com/articles/3155471 5 6

×
Save this presentationTap To Close