SlideShare a Scribd company logo
Introduction	
  to
Cloud	
  Foundry
2016-­‐03-­‐22	
  JJUGナイトセミナー
Toshiaki	
  Maki	
  (@making)
Why	
  PaaS?
Traditional IT
Storage
Servers
Networking
O/S
Middleware
Virtualization
Data
Applications
Runtime
YouManage
O/S
IaaS
Storage
Servers
Networking
Middleware
Virtualization
Data
Applications
RuntimeYouManage
IaaSProvider
PaaS
Storage
Servers
Networking
Middleware
Virtualization
Data
Applications
Runtime
O/S
Business	
  Value,	
  Agility	
  &	
  Cost	
  Savings
YouManage
PaaSProvider
•オープンソースのPaaS基盤
•Cloud Foundry Foundationで開発されて
いる、ベンダロックインを回避
•パブリッククラウド / プライベートクラウ
ド問わず、マルチクラウドに対応
https://github.com/cloudfoundry
Cloud	
  Foundry	
  Foundation
PLATINUM
GOLD
SILVER
https://www.cloudfoundry.org/membership/members/
Certified	
  Certified	
  Providers
CenturyLink	
  AppFog HPE	
  Helion
Cloud	
  Foundry
Huawei
FusionStage
IBM	
  Bluemix
Pivotal	
  Cloud	
  Foundry SAP	
  HANA
Cloud	
  Platform
Swisscom
Application	
  Cloud https://www.cloudfoundry.org/use/cloud-­‐foundry-­‐certified/
Structure
Spring  Cloud Spring  Boot
Cloud  Foundry
BOSH
AWSVMWareOpenStack
Application	
  Framework
Runtime	
  Platform
Infrastructure	
  Automation
Infrastructure
Azure
Contract:	
  Cloud	
  Provider	
  Interface
Contract:	
  12	
  Factor	
  App
Contract:	
  BOSH	
  Release
Java  EE
GCP
Cloud	
  Foundryの使い方
Login
$  cf login  -­‐a  api.run.pivotal.io
$  cf login  -­‐a  api.local.pcfdev.io
Pivotal	
  Web	
  Services
Local	
  (PCF	
  Dev)
$  cf login  -­‐a  paas-­‐jp1-­‐ecl.api.ntt.com
Enterprise	
  Cloud	
  2.0	
  (NTT	
  Com)
<Endpoint>
プロバイダーごとに
異なるエンドポイントを
設定すれば以降は基本同じ
Deploy	
  Java	
  Application	
  (Spring	
  Boot)
$  git clone  https://github.com/making/hello-­‐pws
$  cd  hello-­‐pws
$  mvn package
$  cf push  hello  -­‐p  target/hello-­‐pws.jar
hello	
  world
Host	
  name	
  
(subdomain)
=	
  App	
  name
Domain	
  name
-­‐nで指定可能
Deploy	
  Java	
  Application	
  (Java	
  EE)
$  git clone  https://github.com/making/hello-­‐pws-­‐javaee
$  cd  hello-­‐pws-­‐javaee
$  mvn package
$  cf push  hello  -­‐p  target/hello-­‐pws.war ¥
-­‐b  https://github.com/cloudfoundry/ibm-­‐websphere-­‐liberty-­‐buildpack.git ¥
-­‐-­‐no-­‐start
$  cf set-­‐env hello  IBM_LIBERTY_LICENSE  <License Number>
$  cf set-­‐env hello  IBM_JVM_LICENSE  < License Number >
$  cf start  hello
IBM_LIBERTY_LICENSE IBM_JVM_LICENSE
WebSphere	
  Liberty	
  Profileの場合
ß Search	
  " D/N:	
  *********"	
  for	
  License	
  Number
Deploy	
  Java	
  Application	
  (Java	
  EE)
$  zip  target/hello-­‐pws.zip target/hello-­‐pws.war
$  cf push  hello  -­‐p  target/hello-­‐pws.zip ¥
-­‐b  https://github.com/matf/wildfly-­‐buildpack
WildFlyの場合
Scaling
$  cf scale  hello  -­‐i 4
$  cf scale  hello  -­‐m  2g
Instance
Memory
Cloud	
  Foundryの仕組み
Architecture	
  (Simplified)
Cloud	
  Controller
Blobstore DB
Cell
cf push
http://...
CC	
  API
Containers
Router
[Step1]	
  Upload
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
App
[Step1]	
  Upload
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
App
[Step2]	
  Stage
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
Runtime
App
JRE,	
  App	
  Server	
  
etc..
[Step2]	
  Stage
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
Runtime
App
Droplet
[Step2]	
  Stage
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
Upload
[Step2]	
  Stage
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
[Step3]	
  Start
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
[Step3]	
  Start
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
[Step3]	
  Start
Cloud	
  Controller
Blobstore DB
Cell
cf push CC	
  API
Router
[Step3]	
  Start
Cloud	
  Controller
Blobstore DB
Cell
http://…
CC	
  API
Router
Scale	
  out
Cloud	
  Controller
Blobstore DB
Cell
http://…
CC	
  API
Routercf scale
Scale	
  out
Cloud	
  Controller
Blobstore DB
Cell
http://…
CC	
  API
Routercf scale
Scale	
  out
Cloud	
  Controller
Blobstore DB
Cell
http://…
CC	
  API
Routercf scale
Buildpack
$  cf push
$  cf push  -­‐b  https://github.com/<you>/java-­‐buildpack.git
Auto	
  Detect
Custom	
  Buildpack
Runtime
App
buildpack
https://github.com/cloudfoundry-­‐community/cf-­‐docs-­‐contrib/wiki/Buildpacks
Dockerイメージや.NETアプリにも対応
$  cf push  hello-­‐docker -­‐o  cloudfoundry/lattice-­‐app
Cell
<Docker Image	
  Name>
Cloud	
  Foundryのその他機能
Organization	
  
/	
  Space
Service Log
Blue/Green
Deployment
HA
Organization	
  /	
  Space
CF	
  Installation
OrganizationOrganizationOrganization
Space Space Space
User,	
  Role,	
  Quota	
  
Development,
Staging,
Production
$  cf login  -­‐a  https://api.run.pivotal.io
OK  
Targeted  org  maki-­‐org  
Targeted  space  development  
API  endpoint:  https://api.run.pivotal.io
(API  version:  2.51.0)  
User:  maki@example.com
Org:  maki-­‐org  
Space:  development
Organization	
  /	
  Space
$  cf create-­‐org  jjug
$  cf create-­‐space  -­‐o  jjug production
$  cf target  -­‐o  jjug -­‐s  production
$  cf create-­‐user  maki password
$  cf set-­‐org-­‐role  maki jjug OrgManager
$  cf set-­‐space-­‐role  maki jjug ¥
production  SpaceManager
Create	
  Organization	
  /	
  Space
Create	
  User	
  /	
  Role
Service
データベースやメッセージキューなどのバックエンドサービス
はアプリケーションにアタッチして使用する。
接続情報は環境変数から取得。
http://12factor.net/backing-­‐services
$  cf marketplace 利用可能なサービス一覧。
(プロバイダーごとに異なる)
Create	
  &	
  Bind	
  Service
$  cf create-­‐service  cleardb spark  mydb
$  cf bind-­‐service  hello  mydb
<Service	
  Name> <Plan	
  Name> <Service	
  Instance	
  Name>
<Service	
  Instance	
  Name><App	
  Name>
MySQLのサービス
環境変数 VCAP_SERVICES
{"cleardb":  [{"credentials":  {
"hostname":  "us-­‐cdbr-­‐iron-­‐east-­‐03.cleardb.net",
"jdbcUrl":  "jdbc:mysql://us-­‐cdbr-­‐iron-­‐east-­‐03.cleardb.net/ad_1191b396cc81848",
"name":  "ad_1191b396cc81848",
"password":  "67674107",
"port":  "3306",
"uri":  "mysql://b6f7c089a1680f:67674107@...",
"username":  "b6f7c089a1680f"},
"label":  "cleardb",  
"name":  "mydb",  ...}]}
環境変数 VCAP_SERVICES
spring.datasource.url=${vcap.services.mydb.credentials.jdbcUrl}
spring.datasource.username=${vcap.services.mydb.credentials.username}
spring.datasource.password=${vcap.services.mydb.credentials.password}
String  json =  System.getenv("VCAP_SERVICES");
//  Parse  JSON  ...
Spring Bootの場合 (application-­‐cloud.properties)
一般的なJavaアプリケーションの場合
実はBuildpackにより、自動でDataSourceなどのBeanが差し替えられるのでこの設定は不要
Service	
  Broker	
  /	
  User	
  Provided	
  Service
Application
Service	
  Broker
Service	
  Instance
User	
  Provided	
  Service
Managed	
  Services
MySQL
Redis
RabbitMQ Oracle	
  DB
create-­‐user-­‐provided-­‐servicecreate-­‐service
bind-­‐service
marketplace
User	
  Provided	
  Service
$  cf create-­‐user-­‐provided-­‐service  mydb ¥
-­‐p	
  '{"username"	
  :	
  "xxx",	
  "password"	
  :	
  "xxx",	
  	
  
"port"	
  :	
  "xxx",	
  "	
  jdbcUrl"	
  :	
  "xxx"}'
$  cf bind-­‐service  hello  mydb
自前のサービス(Oracle等)
Log
$  cf logs  hello
標準出力の
ストリーム
3rd Party	
  Log	
  Managers
$  cf create-­‐user-­‐provided-­‐service  mylog ¥
-­‐l  syslog://logs.papertrailapp.com:36129
$  cf bind-­‐service  hello  mylog
Blue/Green	
  Deployment
• デプロイ時のダウンタイムを0に近づける手法
V1
Router
$  cf push  v1  -­‐n  app
Blue/Green	
  Deployment
• デプロイ時のダウンタイムを0に近づける手法
V1
Router$  cf push  v2  -­‐n  app-­‐g
V2
Blue/Green	
  Deployment
• デプロイ時のダウンタイムを0に近づける手法
V1
Router$  cf map-­‐route  v2  example.com -­‐n  app
V2
Blue/Green	
  Deployment
• デプロイ時のダウンタイムを0に近づける手法
V1
Router$  cf unmap-­‐route  v1  example.com -­‐n  app
V2
Blue/Green	
  Deployment
• デプロイ時のダウンタイムを0に近づける手法
V1
Router$  cf unmap-­‐route  v1  example.com -­‐n  app
V2 😊
Blue/Green	
  Deployment
• デプロイ時のダウンタイムを0に近づける手法
V1
Router$  cf delete  v1
V2 😊
Blue/Green	
  Deployment
• デプロイ時のダウンタイムを0に近づける手法
Router
V2
$  cf unmap-­‐route  v2  example.com -­‐n  app-­‐g
Blue/Green	
  Deployment
V1
Router
V2 😱
🔥
Blue/Green	
  Deployment
V1
Router
V2 😱
🔥
$  cf map-­‐route  v1  example.com -­‐n  app
Blue/Green	
  Deployment
V1
Router
V2 😱
🔥
$  cf unmap-­‐route  v2  example.com -­‐n  app
AutopilotPlugin
$  cf zero-­‐downtime-­‐push  app  ¥
-­‐f  manifest.yml
https://github.com/concourse/autopilot
Production向けのデプロイ(e.g.	
  100インスタンス)の場合、少しずつスケールさせるべき (by	
  my	
  teacher	
  @shinji62)
https://github.com/krujos/scaleover-­‐plugin のようなプラグインが便利
Application
(Container) Level
Process
Level
VM
Level
Availability Zone
(Rack)	
  Level
CF	
  Runtime
4	
  levels	
  of	
  HA
CF	
  Runtime
A B C D🔥
B
CF	
  Runtime
A B C D
Process🔥
Monit
CF	
  Runtime
A B C D
Process
VM🔥
Zone1
ABCD
🔥
Zone2
ABCD
Supported	
   by	
  Diego Supported	
   by	
  Bosh
Container
12	
  Factor	
  App
http://12factor.net/
Cloud	
  Foundryは
12	
  Factor	
  App
の全てを満たす
Cloud	
  Foundry by	
  
Cloud	
  Foundry	
  by	
  
Pivotal	
  Manages Customer	
  Manages
Public	
  
Cloud
Pivotal	
  Web	
  Services Pivotal	
  Cloud	
  Foundry	
  
(on	
  AWS	
  /	
  VMware	
  vCloud Air)
Private	
  
Cloud
Pivotal	
  Cloud	
  Foundry
(on	
  OpenStack /	
  VMWare	
  vSphere)
Pivotal	
  Web	
  Services
最新版のCFを
手軽に試せる
https://run.pivotal.io
• AWS上でPivotalがホストする
Cloud	
  Foundry
• $0.03/GB時間 のメモリ課金
• 60日間の試用期間
チュートリアル
Pivotal	
  Cloud	
  Foundry
• 専用Cloud Foundry環境を作るた
めの商用パッケージ
• CFをGUIで容易にインストールす
るためのOps Managerと実行環境
(=CF)のElastic Runtimeで構成
• 利用できるサービス多数
• IaaSとしてAWS, OpenStack,
VMWare vSphere等に対応
• サポート付き
Ops Manager
Apps Manager
RuntimeServices
OSS版とPivotal Cloud	
  Foundryの違い
Riak CS
MongoDB
Gemfire
Neo4J
Redis
DataStax Cassandra
CloudBees Jennkins
Push	
  Notification
Spring	
  Cloud	
  Services
...
MySQL	
  HA
Pivotal	
  Network
Proxy	
  LoadBalancer
Router
Login	
  Server	
  /	
  UAA
Service	
  Broker
Cloud	
  Controller
Diego
Loggregator
Blobstore
OpsManager
Bosh
UI
Addon
Auto	
  Scaling
Identity	
  As	
  A	
  Service
LDAP	
  /	
  AD	
  (SAML)
Metrics	
  Server
Notifications
Ops	
  Metrics
cf CLI
APM	
  (Monitoring)
Apps	
  Manager
Service	
  Marketplace
Certification Documentation Support
PCF
OSS
Open	
  Stack VSphereAWS ...
Announce
Cloud	
  Foundry	
  Tokyo	
  Meetup
#1	
  2016/03/31	
  @	
  六本木Pivotalオフィス
http://bit.ly/cftm1
• Route	
  Services
• Running	
  your	
  application	
  locally	
  
with	
  local-­‐push
• .NET	
  support	
  update
and	
  so	
  on	
  …
Workshop
今日紹介した内容をハンズオン形式で学ぶワークショップ
•3/25	
  16:00-­‐18:00	
  一回目 http://bit.ly/take-­‐me-­‐cf1
•4/13	
  19:00-­‐21:00	
  二回目 http://bit.ly/take-­‐me-­‐cf2
今後も何回か開催する予定

More Related Content

Introduction to Cloud Foundry #JJUG