‹#›© 2016 Pivotal Software, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
Toshiaki Maki (@making)
2016-09-10 Hacker Tackle
#hackt #hackt_k
© 2016 Pivotal Software, Inc. All rights reserved.
Who am I ?
• Toshiaki Maki (@making) http://blog.ik.am
• Sr. Solutions Architect @Pivotal
• Spring Framework enthusiast
bit.ly/hajiboot2
© 2016 Pivotal Software, Inc. All rights reserved.
Who am I ?
• Toshiaki Maki (@making) http://blog.ik.am
• Sr. Solutions Architect @Pivotal
• Spring Framework enthusiast
bit.ly/hajiboot2
© 2016 Pivotal Software, Inc. All rights reserved.
•Cloud Foundry
•Cloud Foundry
•Cloud Foundry
•Cloud Foundry
•Cloud Foundry
https://github.com/making/hacker-tackle-demo
© 2016 Pivotal Software, Inc. All rights reserved.
•Cloud Foundry
•Cloud Foundry
•Cloud Foundry
•Cloud Foundry
•Cloud Foundry
Cloud Foundry
https://github.com/making/hacker-tackle-demo
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
© 2016 Pivotal Software, Inc. All rights reserved.
• PaaS
•Cloud Foundry Foundation
• /
https://github.com/cloudfoundry
© 2016 Pivotal Software, Inc. All rights reserved.
• PaaS
•Cloud Foundry Foundation
• /
https://github.com/cloudfoundry
Cloud Native Platform
© 2016 Pivotal Software, Inc. All rights reserved.
•
•
•
• /
•
•
© 2016 Pivotal Software, Inc. All rights reserved.
•
•
•
• /
•
•
© 2016 Pivotal Software, Inc. All rights reserved.
•
•
•
• /
•
•
!!!!
© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
• (DNS)
•
•
•
•
•
•
© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry everywhere
Cloud Foundry
Cloud Foundry
OSS Pivotal
Cloud Foundry
on
Private Cloud
on
Public Cloud
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
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
© 2016 Pivotal Software, Inc. All rights reserved.
$ cf login -a https://api.local.pcfdev.io --skip-ssl-validation
$ cf login -a https://api.run.pivotal.io
$ cf login -a https://api.system.your-cf.example.com
PCF Dev
Pivotal Web Services
Pivotal Cloud Foundry
https://github.com/cloudfoundry/cli/releases
© 2016 Pivotal Software, Inc. All rights reserved.
cf push
© 2016 Pivotal Software, Inc. All rights reserved.
cf push
© 2016 Pivotal Software, Inc. All rights reserved.
$ cf push hello -p hello.jar
$ cf push hello
glide godep
app nameSpring Boot
© 2016 Pivotal Software, Inc. All rights reserved.
$ cf push hello -p hello.jar
$ cf push hello
glide godep
app nameSpring Boot
func main() {
http.HandleFunc("/", func(w http.ResponseWriter
, r *http.Request) {
fmt.Fprint(w, "Hello World!")
})
http.ListenAndServe(":"+os.Getenv("PORT"), nil);
}
© 2016 Pivotal Software, Inc. All rights reserved.
Hello World
Host name
(subdomain)
=app name
domain name
-n
© 2016 Pivotal Software, Inc. All rights reserved.
cf scale
© 2016 Pivotal Software, Inc. All rights reserved.
cf scale
© 2016 Pivotal Software, Inc. All rights reserved.
$ cf scale app-name -i 4
$ cf scale app-name -m 2g
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Demo
https://www.youtube.com/watch?v=_TpvipmGisc
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Deploying an Application
IaaS Cloud Foundry
Configure Firewall
Configure Service Connectivity
Configure SSL
Configure Load Balancer
Deploy Application
Install Application Runtime
Provision a VM
cf push
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Scaling an Application
IaaS Cloud Foundry
Configure Firewall
Configure Service Connectivity
Configure SSL
Configure Load Balancer
Deploy Application
Install Application Runtime
Provision a VM
cf scale
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Scaling an Application
IaaS Cloud Foundry
Configure Firewall
Configure Service Connectivity
Configure SSL
Configure Load Balancer
Deploy Application
Install Application Runtime
Provision a VM
cf scale
!!
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
http://docs.cloudfoundry.org/concepts/diego/diego-architecture.html
© 2016 Pivotal Software, Inc. All rights reserved.
Architecture (Super Simplified)
Cloud	Controller
Blobstore DB
Cell
cf	push
http://...
CC	API
Containers
Router
© 2016 Pivotal Software, Inc. All rights reserved.
Architecture (Super Simplified)
Cloud	Controller
Blobstore DB
Cell
cf	push
http://...
CC	API
Containers
Router
RunC
© 2016 Pivotal Software, Inc. All rights reserved.
! Upload
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
App
© 2016 Pivotal Software, Inc. All rights reserved.
! Upload
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
App
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
Runtime
App
JRE,	App	Server	
etc..
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
Runtime
App
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
Runtime
App
Droplet
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
Upload
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
Upload
© 2016 Pivotal Software, Inc. All rights reserved.
" Stage
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
# Start
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
# Start
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
# Start
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
# Start
Cloud	Controller
Blobstore DB
Cell
cf	push CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
# Start
Cloud	Controller
Blobstore DB
Cell
http://…
CC	API
Router
© 2016 Pivotal Software, Inc. All rights reserved.
Scale out
Cloud	Controller
Blobstore DB
Cell
http://…
CC	API
Router
cf	scale
© 2016 Pivotal Software, Inc. All rights reserved.
Scale out
Cloud	Controller
Blobstore DB
Cell
http://…
CC	API
Router
cf	scale
© 2016 Pivotal Software, Inc. All rights reserved.
Scale out
Cloud	Controller
Blobstore DB
Cell
http://…
CC	API
Router
cf	scale
© 2016 Pivotal Software, Inc. All rights reserved.
Scale out
Cloud	Controller
Blobstore DB
Cell
http://…
CC	API
Router
cf	scale
© 2016 Pivotal Software, Inc. All rights reserved.
Scale out
Cloud	Controller
Blobstore DB
Cell
http://…
CC	API
Router
cf	scale
© 2016 Pivotal Software, Inc. All rights reserved.
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
$ cf push -b java_buildpack
Manual
© 2016 Pivotal Software, Inc. All rights reserved.
Cell
Docker
© 2016 Pivotal Software, Inc. All rights reserved.
Cell
Docker
© 2016 Pivotal Software, Inc. All rights reserved.
Docker
$ cf push demo-docker 
--docker-image 
cloudfoundry/lattice-app
© 2016 Pivotal Software, Inc. All rights reserved.
Docker
$ cf push demo-docker 
--docker-image 
cloudfoundry/lattice-app
CF
👇 !!
bit.ly/cf-container
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
© 2016 Pivotal Software, Inc. All rights reserved.
•
•
•
• Blue / Green
• Zero Downtime Update
© 2016 Pivotal Software, Inc. All rights reserved.
http://12factor.net/backing-services
© 2016 Pivotal Software, Inc. All rights reserved.
$	cf	marketplace
© 2016 Pivotal Software, Inc. All rights reserved.
$	cf	marketplace
Pivotal Web Services
© 2016 Pivotal Software, Inc. All rights reserved.
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
© 2016 Pivotal Software, Inc. All rights reserved.
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",	"tags":	["mysql",	...],	
		"name":	"mydb",	...}]}
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Go (go-simplejson)
import "github.com/bitly/go-simplejson"
json, _ := simplejson.NewJson([]byte(os.Getenv("VCAP_SERVICES")))
credentials := json.Get("cleardb").GetIndex(0)
.Get("credentials").MustMap()
uri, _ := credentials["uri"].(string)
u, _ := url.Parse(uri)
url := fmt.Sprintf("%s@tcp(%s)%s", u.User.String(),
u.Host, u.Path)
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Go (go-cfenv)
import cfenv "github.com/cloudfoundry-community/go-cfenv"
appEnv, err := cfenv.Current()
mydb, err := appEnv.Services.WithName("mydb")
uri, _ := mydb.Credentials["uri"].(string)
u, _ := url.Parse(uri)
url := fmt.Sprintf("%s@tcp(%s)%s", u.User.String(),
u.Host, u.Path)
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Java (Jackson)
JsonNode credentials = objectMapper
.readTree(System.getenv("VCAP_SERVICES"))
.get("cleardb").get(0).get("credentials");
String url = credentials.get("jdbcUrl").asText();
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Java (Spring)
@Configuration
public class CloudConfig extends AbstractCloudConfig {
@Bean
DataSource dataSource() {
return connectionFactory().dataSource();
}
}
http://cloud.spring.io/spring-cloud-connectors/
Spring Cloud Connectors
© 2016 Pivotal Software, Inc. All rights reserved.
Service Broker / User Provided
Application
Service	Broker
Service	Instance
User	Provided	Service
Managed	Services
MySQL
Redis
RabbitMQ Oracle	DB
create-user-provided-servicecreate-service
bind-service
marketplace
© 2016 Pivotal Software, Inc. All rights reserved.
User Provided Service
$	cf	create-user-provided-service	mydb		
												-p	'{"username"	:	"xxx",	"password"	:	"xxx",			
																			"port"	:	"xxx",	"	jdbcUrl"	:	"xxx"}'
$	cf	bind-service	hello	mydb
(Oracle DB )
© 2016 Pivotal Software, Inc. All rights reserved.
Log
$	cf	logs	hello
© 2016 Pivotal Software, Inc. All rights reserved.
3rd Party Log Managers
$ cf create-user-provided-service mylog 
-l syslog://xxxxxxxx-logit.io:36129
$ cf bind-service hello mylog
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
PCF Metrics https://metrics.run.pivotal.io/ for Pivotal Web Services
© 2016 Pivotal Software, Inc. All rights reserved.
4 Layers HA
PCF
3. Resurrector
restarts failed
VMs
App Fail
Platform
Fail
VM Fail Rack Fail
PCF
A B C
B
1. 2.
PCF
VM
PCF
A B C
Process
PCF
A B C
VM1 VM2
OS,
Mware
VM
PCF VM kill
3.
VM3
OS,
Mware
OS,
Mware
PCF
Zone
Distribution
4.
Zone 2Zone 1
VM1 VM2
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Demo
`
https://www.youtube.com/watch?v=26RrBiBymeA
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
• 0
V1
Router
$ cf push v1 -n app
app.example.com
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com
app.example.com
$ cf push v2 -n app-g
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com
app.example.com
app.example.com
$ cf map-route v2 example.com -n app
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com
app.example.com
$ cf unmap-route v1 example.com -n app
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com
app.example.com
😊
$ cf unmap-route v1 example.com -n app
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com
app.example.com
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
app-g.example.com
app.example.com
😱
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com
app.example.com
😱
🔥
app.example.com
$ cf map-route v1 example.com -n app
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com 😱
🔥
app.example.com
$ cf unmap-route v2 example.com -n app
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
V1
Router
V2
app-g.example.com
app.example.com
😊
$ cf delete v1
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
Router
V2
app-g.example.com
app.example.com
😊
$ cf delete v1
© 2016 Pivotal Software, Inc. All rights reserved.
Blue/Green Deployment
Router
V2
app.example.com
$ cf unmap-route v2 example.com -n app-g
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Demo
https://www.youtube.com/watch?v=2LtsURDvMF0
© 2016 Pivotal Software, Inc. All rights reserved.
Zero Downtime Update
• ) JVM
https://github.com/concourse/autopilot
$ cf zero-downtime-push app-name -f manifest.yml
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Demo
https://www.youtube.com/watch?v=mbvg8wijs4Y
© Copyright 2016 Pivotal. All rights reserved. 66
Upgrade and patch with rolling “canary” deploys
X YM NA B
A,B,M,N,X,Y - Application instances
- VM prior to update
© Copyright 2016 Pivotal. All rights reserved. 67
Upgrade and patch with rolling “canary” deploys
X YM NA B
Apps redeployed to clear VMs
X YM NA B
© Copyright 2016 Pivotal. All rights reserved. 68
Upgrade and patch with rolling “canary” deploys
X YM NA B
X YM NA B
Update introduced. If the tests
pass, keep going
X YM NA B
© Copyright 2016 Pivotal. All rights reserved. 69
Upgrade and patch with rolling “canary” deploys
X YM NA B
X YM NA B
X YM NA B
Apps redeployed to updated VMs
X YM NA B
© Copyright 2016 Pivotal. All rights reserved. 70
Upgrade and patch with rolling “canary” deploys
X YM NA B
X YM NA B
X YM NA B
X YM NA B
Remaining VMs updated same way
X YM NA B
© Copyright 2016 Pivotal. All rights reserved. 71
Upgrade and patch with rolling “canary” deploys
X YM NA B
X YM NA B
X YM NA B
X YM NA B
X YM NA B
Automated, No downtime
Atomic rolling update
X YM NA B
© Copyright 2016 Pivotal. All rights reserved. 72
Upgrade and patch with rolling “canary” deploys
© 2016 Pivotal Software, Inc. All rights reserved.
New Features
•Routing Service
•TCP Routing
•Persistent Volume
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
Yes
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
Yes
Yes
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
Yes
Yes
No
(OSS)
© 2016 Pivotal Software, Inc. All rights reserved.
CF PCF Dev
Pivotal
Web Services
Pivotal
Cloud Foundry
Cloud Foundry
(OSS)
Yes
Yes
No
( )
No
( )
No
( )
Yes
Yes
No
(OSS)
© 2016 Pivotal Software, Inc. All rights reserved.
PCF Dev
• Cloud Foundry (on VirtualBox)
• http://pcfdev.io https://docs.pivotal.io/pcf-dev
• cf dev start / stop
•
• Redis
• RabbitMQ
• MySQL
• Spring Cloud Services
© 2016 Pivotal Software, Inc. All rights reserved.
Pivotal Web Services
• https://run.pivotal.io/
• AWS Pivotal Cloud Foundry
• 1GB $0.03/
• 1: Java 1GB ➡ 2200 /
• 2: Go 64MB ➡ 135 / , 8MB➡ 17 /
• $87 (2GB 2 , 1 )
•
• PCF Metrics, Auto Scaler (Docker )
© 2016 Pivotal Software, Inc. All rights reserved.
Pivotal Cloud Foundry
• https://pivotal.io/platform
• Cloud Foundry
• AppsManager
• vSphere, AWS, OpenStack CF
(OpsManager) Azure
GCP
• OSS
All in One
© 2016 Pivotal Software, Inc. All rights reserved.
Spring Boot [ ]
• http://bit.ly/hajiboot2
• Java Spring
Boot 1.4
• Pivotal Web Services
Blue/Green
© 2016 Pivotal Software, Inc. All rights reserved.
Spring Boot [ ]
• http://bit.ly/hajiboot2
• Java Spring
Boot 1.4
• Pivotal Web Services
Blue/Green
Cloud Foundry!!!!
© 2016 Pivotal Software, Inc. All rights reserved.
Spring Boot [ ]
• http://bit.ly/hajiboot2
• Java Spring
Boot 1.4
• Pivotal Web Services
Blue/Green
Cloud Foundry!!!!
!!

今すぐ始めるCloud Foundry #hackt #hackt_k

  • 1.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved. Cloud Foundry Toshiaki Maki (@making) 2016-09-10 Hacker Tackle #hackt #hackt_k
  • 2.
    © 2016 PivotalSoftware, Inc. All rights reserved. Who am I ? • Toshiaki Maki (@making) http://blog.ik.am • Sr. Solutions Architect @Pivotal • Spring Framework enthusiast bit.ly/hajiboot2
  • 3.
    © 2016 PivotalSoftware, Inc. All rights reserved. Who am I ? • Toshiaki Maki (@making) http://blog.ik.am • Sr. Solutions Architect @Pivotal • Spring Framework enthusiast bit.ly/hajiboot2
  • 4.
    © 2016 PivotalSoftware, Inc. All rights reserved. •Cloud Foundry •Cloud Foundry •Cloud Foundry •Cloud Foundry •Cloud Foundry https://github.com/making/hacker-tackle-demo
  • 5.
    © 2016 PivotalSoftware, Inc. All rights reserved. •Cloud Foundry •Cloud Foundry •Cloud Foundry •Cloud Foundry •Cloud Foundry Cloud Foundry https://github.com/making/hacker-tackle-demo
  • 6.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry
  • 7.
    © 2016 PivotalSoftware, Inc. All rights reserved. • PaaS •Cloud Foundry Foundation • / https://github.com/cloudfoundry
  • 8.
    © 2016 PivotalSoftware, Inc. All rights reserved. • PaaS •Cloud Foundry Foundation • / https://github.com/cloudfoundry Cloud Native Platform
  • 9.
    © 2016 PivotalSoftware, Inc. All rights reserved. • • • • / • •
  • 10.
    © 2016 PivotalSoftware, Inc. All rights reserved. • • • • / • •
  • 11.
    © 2016 PivotalSoftware, Inc. All rights reserved. • • • • / • • !!!!
  • 12.
    © 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry • (DNS) • • • • • •
  • 13.
    © 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry everywhere Cloud Foundry Cloud Foundry OSS Pivotal Cloud Foundry on Private Cloud on Public Cloud
  • 14.
    Structure Spring Cloud SpringBoot 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
  • 15.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry
  • 16.
    © 2016 PivotalSoftware, Inc. All rights reserved. $ cf login -a https://api.local.pcfdev.io --skip-ssl-validation $ cf login -a https://api.run.pivotal.io $ cf login -a https://api.system.your-cf.example.com PCF Dev Pivotal Web Services Pivotal Cloud Foundry https://github.com/cloudfoundry/cli/releases
  • 17.
    © 2016 PivotalSoftware, Inc. All rights reserved. cf push
  • 18.
    © 2016 PivotalSoftware, Inc. All rights reserved. cf push
  • 19.
    © 2016 PivotalSoftware, Inc. All rights reserved. $ cf push hello -p hello.jar $ cf push hello glide godep app nameSpring Boot
  • 20.
    © 2016 PivotalSoftware, Inc. All rights reserved. $ cf push hello -p hello.jar $ cf push hello glide godep app nameSpring Boot func main() { http.HandleFunc("/", func(w http.ResponseWriter , r *http.Request) { fmt.Fprint(w, "Hello World!") }) http.ListenAndServe(":"+os.Getenv("PORT"), nil); }
  • 21.
    © 2016 PivotalSoftware, Inc. All rights reserved. Hello World Host name (subdomain) =app name domain name -n
  • 22.
    © 2016 PivotalSoftware, Inc. All rights reserved. cf scale
  • 23.
    © 2016 PivotalSoftware, Inc. All rights reserved. cf scale
  • 24.
    © 2016 PivotalSoftware, Inc. All rights reserved. $ cf scale app-name -i 4 $ cf scale app-name -m 2g
  • 25.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Demo https://www.youtube.com/watch?v=_TpvipmGisc
  • 26.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Deploying an Application IaaS Cloud Foundry Configure Firewall Configure Service Connectivity Configure SSL Configure Load Balancer Deploy Application Install Application Runtime Provision a VM cf push
  • 27.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Scaling an Application IaaS Cloud Foundry Configure Firewall Configure Service Connectivity Configure SSL Configure Load Balancer Deploy Application Install Application Runtime Provision a VM cf scale
  • 28.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Scaling an Application IaaS Cloud Foundry Configure Firewall Configure Service Connectivity Configure SSL Configure Load Balancer Deploy Application Install Application Runtime Provision a VM cf scale !!
  • 29.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry
  • 30.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry http://docs.cloudfoundry.org/concepts/diego/diego-architecture.html
  • 31.
    © 2016 PivotalSoftware, Inc. All rights reserved. Architecture (Super Simplified) Cloud Controller Blobstore DB Cell cf push http://... CC API Containers Router
  • 32.
    © 2016 PivotalSoftware, Inc. All rights reserved. Architecture (Super Simplified) Cloud Controller Blobstore DB Cell cf push http://... CC API Containers Router RunC
  • 33.
    © 2016 PivotalSoftware, Inc. All rights reserved. ! Upload Cloud Controller Blobstore DB Cell cf push CC API Router App
  • 34.
    © 2016 PivotalSoftware, Inc. All rights reserved. ! Upload Cloud Controller Blobstore DB Cell cf push CC API Router App
  • 35.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router
  • 36.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router
  • 37.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router Runtime App JRE, App Server etc..
  • 38.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router Runtime App
  • 39.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router Runtime App Droplet
  • 40.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router Upload
  • 41.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router Upload
  • 42.
    © 2016 PivotalSoftware, Inc. All rights reserved. " Stage Cloud Controller Blobstore DB Cell cf push CC API Router
  • 43.
    © 2016 PivotalSoftware, Inc. All rights reserved. # Start Cloud Controller Blobstore DB Cell cf push CC API Router
  • 44.
    © 2016 PivotalSoftware, Inc. All rights reserved. # Start Cloud Controller Blobstore DB Cell cf push CC API Router
  • 45.
    © 2016 PivotalSoftware, Inc. All rights reserved. # Start Cloud Controller Blobstore DB Cell cf push CC API Router
  • 46.
    © 2016 PivotalSoftware, Inc. All rights reserved. # Start Cloud Controller Blobstore DB Cell cf push CC API Router
  • 47.
    © 2016 PivotalSoftware, Inc. All rights reserved. # Start Cloud Controller Blobstore DB Cell http://… CC API Router
  • 48.
    © 2016 PivotalSoftware, Inc. All rights reserved. Scale out Cloud Controller Blobstore DB Cell http://… CC API Router cf scale
  • 49.
    © 2016 PivotalSoftware, Inc. All rights reserved. Scale out Cloud Controller Blobstore DB Cell http://… CC API Router cf scale
  • 50.
    © 2016 PivotalSoftware, Inc. All rights reserved. Scale out Cloud Controller Blobstore DB Cell http://… CC API Router cf scale
  • 51.
    © 2016 PivotalSoftware, Inc. All rights reserved. Scale out Cloud Controller Blobstore DB Cell http://… CC API Router cf scale
  • 52.
    © 2016 PivotalSoftware, Inc. All rights reserved. Scale out Cloud Controller Blobstore DB Cell http://… CC API Router cf scale
  • 53.
    © 2016 PivotalSoftware, Inc. All rights reserved. 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 $ cf push -b java_buildpack Manual
  • 54.
    © 2016 PivotalSoftware, Inc. All rights reserved. Cell Docker
  • 55.
    © 2016 PivotalSoftware, Inc. All rights reserved. Cell Docker
  • 56.
    © 2016 PivotalSoftware, Inc. All rights reserved. Docker $ cf push demo-docker --docker-image cloudfoundry/lattice-app
  • 57.
    © 2016 PivotalSoftware, Inc. All rights reserved. Docker $ cf push demo-docker --docker-image cloudfoundry/lattice-app CF 👇 !! bit.ly/cf-container
  • 58.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry
  • 59.
    © 2016 PivotalSoftware, Inc. All rights reserved. • • • • Blue / Green • Zero Downtime Update
  • 60.
    © 2016 PivotalSoftware, Inc. All rights reserved. http://12factor.net/backing-services
  • 61.
    © 2016 PivotalSoftware, Inc. All rights reserved. $ cf marketplace
  • 62.
    © 2016 PivotalSoftware, Inc. All rights reserved. $ cf marketplace Pivotal Web Services
  • 63.
    © 2016 PivotalSoftware, Inc. All rights reserved. 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
  • 64.
    © 2016 PivotalSoftware, Inc. All rights reserved. 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", "tags": ["mysql", ...], "name": "mydb", ...}]}
  • 65.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Go (go-simplejson) import "github.com/bitly/go-simplejson" json, _ := simplejson.NewJson([]byte(os.Getenv("VCAP_SERVICES"))) credentials := json.Get("cleardb").GetIndex(0) .Get("credentials").MustMap() uri, _ := credentials["uri"].(string) u, _ := url.Parse(uri) url := fmt.Sprintf("%s@tcp(%s)%s", u.User.String(), u.Host, u.Path)
  • 66.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Go (go-cfenv) import cfenv "github.com/cloudfoundry-community/go-cfenv" appEnv, err := cfenv.Current() mydb, err := appEnv.Services.WithName("mydb") uri, _ := mydb.Credentials["uri"].(string) u, _ := url.Parse(uri) url := fmt.Sprintf("%s@tcp(%s)%s", u.User.String(), u.Host, u.Path)
  • 67.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Java (Jackson) JsonNode credentials = objectMapper .readTree(System.getenv("VCAP_SERVICES")) .get("cleardb").get(0).get("credentials"); String url = credentials.get("jdbcUrl").asText();
  • 68.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Java (Spring) @Configuration public class CloudConfig extends AbstractCloudConfig { @Bean DataSource dataSource() { return connectionFactory().dataSource(); } } http://cloud.spring.io/spring-cloud-connectors/ Spring Cloud Connectors
  • 69.
    © 2016 PivotalSoftware, Inc. All rights reserved. Service Broker / User Provided Application Service Broker Service Instance User Provided Service Managed Services MySQL Redis RabbitMQ Oracle DB create-user-provided-servicecreate-service bind-service marketplace
  • 70.
    © 2016 PivotalSoftware, Inc. All rights reserved. User Provided Service $ cf create-user-provided-service mydb -p '{"username" : "xxx", "password" : "xxx", "port" : "xxx", " jdbcUrl" : "xxx"}' $ cf bind-service hello mydb (Oracle DB )
  • 71.
    © 2016 PivotalSoftware, Inc. All rights reserved. Log $ cf logs hello
  • 72.
    © 2016 PivotalSoftware, Inc. All rights reserved. 3rd Party Log Managers $ cf create-user-provided-service mylog -l syslog://xxxxxxxx-logit.io:36129 $ cf bind-service hello mylog
  • 73.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. PCF Metrics https://metrics.run.pivotal.io/ for Pivotal Web Services
  • 74.
    © 2016 PivotalSoftware, Inc. All rights reserved. 4 Layers HA PCF 3. Resurrector restarts failed VMs App Fail Platform Fail VM Fail Rack Fail PCF A B C B 1. 2. PCF VM PCF A B C Process PCF A B C VM1 VM2 OS, Mware VM PCF VM kill 3. VM3 OS, Mware OS, Mware PCF Zone Distribution 4. Zone 2Zone 1 VM1 VM2
  • 75.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Demo ` https://www.youtube.com/watch?v=26RrBiBymeA
  • 76.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment • 0 V1 Router $ cf push v1 -n app app.example.com
  • 77.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com app.example.com $ cf push v2 -n app-g
  • 78.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com app.example.com app.example.com $ cf map-route v2 example.com -n app
  • 79.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com app.example.com $ cf unmap-route v1 example.com -n app
  • 80.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com app.example.com 😊 $ cf unmap-route v1 example.com -n app
  • 81.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com app.example.com
  • 82.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router app-g.example.com app.example.com 😱
  • 83.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com app.example.com 😱 🔥 app.example.com $ cf map-route v1 example.com -n app
  • 84.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com 😱 🔥 app.example.com $ cf unmap-route v2 example.com -n app
  • 85.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment V1 Router V2 app-g.example.com app.example.com 😊 $ cf delete v1
  • 86.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment Router V2 app-g.example.com app.example.com 😊 $ cf delete v1
  • 87.
    © 2016 PivotalSoftware, Inc. All rights reserved. Blue/Green Deployment Router V2 app.example.com $ cf unmap-route v2 example.com -n app-g
  • 88.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Demo https://www.youtube.com/watch?v=2LtsURDvMF0
  • 89.
    © 2016 PivotalSoftware, Inc. All rights reserved. Zero Downtime Update • ) JVM https://github.com/concourse/autopilot $ cf zero-downtime-push app-name -f manifest.yml
  • 90.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Demo https://www.youtube.com/watch?v=mbvg8wijs4Y
  • 91.
    © Copyright 2016Pivotal. All rights reserved. 66 Upgrade and patch with rolling “canary” deploys X YM NA B A,B,M,N,X,Y - Application instances - VM prior to update
  • 92.
    © Copyright 2016Pivotal. All rights reserved. 67 Upgrade and patch with rolling “canary” deploys X YM NA B Apps redeployed to clear VMs X YM NA B
  • 93.
    © Copyright 2016Pivotal. All rights reserved. 68 Upgrade and patch with rolling “canary” deploys X YM NA B X YM NA B Update introduced. If the tests pass, keep going X YM NA B
  • 94.
    © Copyright 2016Pivotal. All rights reserved. 69 Upgrade and patch with rolling “canary” deploys X YM NA B X YM NA B X YM NA B Apps redeployed to updated VMs X YM NA B
  • 95.
    © Copyright 2016Pivotal. All rights reserved. 70 Upgrade and patch with rolling “canary” deploys X YM NA B X YM NA B X YM NA B X YM NA B Remaining VMs updated same way X YM NA B
  • 96.
    © Copyright 2016Pivotal. All rights reserved. 71 Upgrade and patch with rolling “canary” deploys X YM NA B X YM NA B X YM NA B X YM NA B X YM NA B Automated, No downtime Atomic rolling update X YM NA B
  • 97.
    © Copyright 2016Pivotal. All rights reserved. 72 Upgrade and patch with rolling “canary” deploys
  • 98.
    © 2016 PivotalSoftware, Inc. All rights reserved. New Features •Routing Service •TCP Routing •Persistent Volume
  • 99.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Cloud Foundry
  • 100.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS)
  • 101.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS)
  • 102.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes
  • 103.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes
  • 104.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes
  • 105.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes
  • 106.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( )
  • 107.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( )
  • 108.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( )
  • 109.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( )
  • 110.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( )
  • 111.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( )
  • 112.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( ) Yes
  • 113.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( ) Yes
  • 114.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( ) Yes Yes
  • 115.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( ) Yes Yes
  • 116.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( ) Yes Yes No (OSS)
  • 117.
    © 2016 PivotalSoftware, Inc. All rights reserved. CF PCF Dev Pivotal Web Services Pivotal Cloud Foundry Cloud Foundry (OSS) Yes Yes No ( ) No ( ) No ( ) Yes Yes No (OSS)
  • 118.
    © 2016 PivotalSoftware, Inc. All rights reserved. PCF Dev • Cloud Foundry (on VirtualBox) • http://pcfdev.io https://docs.pivotal.io/pcf-dev • cf dev start / stop • • Redis • RabbitMQ • MySQL • Spring Cloud Services
  • 119.
    © 2016 PivotalSoftware, Inc. All rights reserved. Pivotal Web Services • https://run.pivotal.io/ • AWS Pivotal Cloud Foundry • 1GB $0.03/ • 1: Java 1GB ➡ 2200 / • 2: Go 64MB ➡ 135 / , 8MB➡ 17 / • $87 (2GB 2 , 1 ) • • PCF Metrics, Auto Scaler (Docker )
  • 120.
    © 2016 PivotalSoftware, Inc. All rights reserved. Pivotal Cloud Foundry • https://pivotal.io/platform • Cloud Foundry • AppsManager • vSphere, AWS, OpenStack CF (OpsManager) Azure GCP • OSS All in One
  • 121.
    © 2016 PivotalSoftware, Inc. All rights reserved. Spring Boot [ ] • http://bit.ly/hajiboot2 • Java Spring Boot 1.4 • Pivotal Web Services Blue/Green
  • 122.
    © 2016 PivotalSoftware, Inc. All rights reserved. Spring Boot [ ] • http://bit.ly/hajiboot2 • Java Spring Boot 1.4 • Pivotal Web Services Blue/Green Cloud Foundry!!!!
  • 123.
    © 2016 PivotalSoftware, Inc. All rights reserved. Spring Boot [ ] • http://bit.ly/hajiboot2 • Java Spring Boot 1.4 • Pivotal Web Services Blue/Green Cloud Foundry!!!! !!