More Related Content Similar to JSUG20171027-spfingboot-k8s-ocp (20) More from Nobuhiro Sue (20) JSUG20171027-spfingboot-k8s-ocp1. JSUG勉強会 2017年その8
Spring Boot on
Kubernetes/OpenShift
2017年 10月 27日
レッドハット株式会社 テクニカルセールス本部
シニアソリューションアーキテクト
須江 信洋 (nosue@redhat.com / @nobusue)
3. 自己紹介
• 須江 信洋(すえ のぶひろ)
– Mail: nosue@redhat.com
– Twitter: @nobusue
• 約14年JavaEE関連に携わる(1999〜2013)
• Enterprise Mobile製品担当(2012〜2013)
• IoTサービス関連ベンチャー 開発から運用まで
(2014〜2017)
– ストリーミングデータ処理
– マイクロサービス化
– コンテナプラットフォーム構築/運用
3
8. マイクロサービスの課題
l 構築
Ø サービスの境界 / 粒度
Ø ビルド / デプロイの効率化
Ø サービス間連携 (サービスディスカバリ、オーケストレーション、コレオグラフィー)
Ø テスト (サービス単位 / エンドツーエンド)
Ø 自律的な回復
l 運用
Ø サービスの健全性の管理 / 監視
Ø サービス障害対応 (ログ集中管理、トレーサビリティ )
Ø サービス間の依存関係の管理 (バージョニング、データマイグレーション)
Ø パフォーマンス管理 / リソース管理
Ø API管理 (特に外部公開用)
l セキュリティ
Ø 分散環境での認証 / 認可
Ø 暗号化
Ø 監査
8
9. Spring Boot + Spring Cloud
9
https://spring.io/
12 factor app原則に基づいた
シンプル/コンパクトなサービスを
JVMベースで実装
マイクロサービスの課題を
解決するための
抽象化レイヤーを提供
15. Spring Boot -> Kubernetesの課題
• Spring Bootアプリケーションのコンテナ化
– Dockerfile ?
– EXPOSE / VOLUME ?
• Kubernetesへのデプロイ
– YAML ?
– Pod / Service ?
– 環境構築 ?
– アプリケーションへのアクセス ?
15
16. Fabric8 Maven Plugin
• Spring Bootアプリケーションのコンテナ化を簡単に!!
– Dockerfile 不要
– Mavenによるビルドワークフローへの組み込み
• Kubernetes/OpenShiftへのデプロイを簡単に!!
– YAML 不要 (必要十分なデフォルトを補う)
• 必要に応じてYAMLのテンプレートを適用することも可能
• Docker Composeの定義ファイルを利用することも可能
– Pod / Service を自動的に定義
16
https://maven.fabric8.io/
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
19. minikube実行
• 起動
– $ minikube start # VirtualBox
– $ minikube start --vm-driver xhyve # xhyve
• 仮想マシンのIP確認
– $ minikube ip
• ダッシュボード表示
– $ minikube dashboard
• 停止
– $ minikube stop
19 ※ うまく起動しないときは $ minikube delete でVMを削除してからstart
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
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. SpringBoot Appをminikubeにデプロイする(3)
• ビルド
– $ mvn package fabric8:build
– $ mvn fabric8:resource # k8s用リソース生成
• フォアグラウンド実行
– $ mvn fabric8:run
• デプロイ
– $ mvn fabric8:deploy
23
※標準入出力を使うのでタイムアウト等で失敗することがあるが、
再実行すればたいていうまくいく
24. SpringBoot Appをminikubeにデプロイする(4)
• アプリケーションへのアクセス
– PodやServiceには、デフォルトではKubernetesクラスタ内からしか
アクセスできないIPアドレスがアサインされている(仮想ネットワー
クが構成されているため)
• アクセス可能にするための方法は以下
1. ポートフォワードでPodに直接接続する
2. Ingress Routerを有効にする (minikubeではやや面倒)
3. exposecontrollerを使う
• https://github.com/fabric8io/exposecontroller
24
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. 環境構築: minishift
• minishiftとは?
– all in one構成で実行可能なOpenShift
– 全コンポーネントをコンテナベースで実行
• minishift実行方法
– Getting Started with Minishift
• https://docs.openshift.org/latest/minishift/getting-
started/index.html
28
30. minishift実行
• 起動
– $ minishift start # VirtualBox
– $ minishift start --vm-driver xhyve # xhyve
• 仮想マシンのIP確認
– $ minishift ip
• 管理コンソール表示
– $ minishift console
• 停止
– $ minishift stop
30
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
42. • 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
43. プロジェクトへの追加方法
<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>
44. 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適用
45. 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
48. マイクロサービス課題への対応: サービスメッシュ
l マイクロサービス間の連携を透過的に扱うためのレイヤーを提供
Ø HTTPやgRPCなどの低レイヤーの通信を隠蔽(タイムアウト、リトライ等)
Ø サービスディスカバリとルーティング、トラフィック制御
Ø サービス障害の影響を最小化 (例: circuit breaker)
Ø サービス間認証/認可、暗号化
Ø サービス全体のモニタリングとレポーティング
l Kubernetes(コンテナ基盤)上の新たな「ミドルウェア」
Ø Istio (https://istio.io/)
Ø linkerd (https://linkerd.io/)
4
8
49. 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/
52. 詳しくはSpring Fest 2017にて!!
Kamesh Sampath
• Creator of vertx-maven-plugin
• Contributor fabric8 platform
kamesh_sampath
ksampath@redhat.com
kameshsampath
55. 補足: 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
56. 補足: 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