Top Banner
Getting Started with Cloud Foundry Ian Huston, Data Scientist Ian Huston, Data Scientist ODSC London 2016
29

Ian huston getting started with cloud foundry

Apr 13, 2017

Download

Data & Analytics

Jessica Willis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ian huston   getting started with cloud foundry

Getting Started with Cloud Foundry

•  Ian Huston, Data Scientist Ian Huston, Data Scientist

ODSC London 2016

Page 2: Ian huston   getting started with cloud foundry

2 © Copyright 2015 Pivotal. All rights reserved.

Who am I? �  Ian Huston � @ianhuston � www.ianhuston.net � More resources:

https://github.com/ihuston/python-cf-examples

� Data Scientist � Previously a theoretical

physicist using Python for numerical simulations & HPC

Page 3: Ian huston   getting started with cloud foundry

3 © Copyright 2015 Pivotal. All rights reserved.

Aims for this talk Goals: � What is Cloud Foundry and how can it help? � Get a taste of CF as a developer/data scientist Anti-goals: � Understand CF from an operations viewpoint �  Install & run a full Cloud Foundry installation

Page 4: Ian huston   getting started with cloud foundry

4 © Copyright 2015 Pivotal. All rights reserved.

Talk Resources

For the full 2 hour tutorial clone this repo: https://github.com/ihuston/python-cf-examples

Page 5: Ian huston   getting started with cloud foundry

What is Cloud Foundry? http://cloudfoundry.org

Open Source

Multi-Cloud Platform

Simple App Deployment, Scaling & Availability

Page 6: Ian huston   getting started with cloud foundry

Cloud Applications Haiku Here is my source code Run it on the cloud for me I do not care how.

-  Onsi Fakhouri @onsijoe

Page 7: Ian huston   getting started with cloud foundry

How can data scientists use CF?

Page 8: Ian huston   getting started with cloud foundry

Data Services Easy control of incoming data

Page 9: Ian huston   getting started with cloud foundry

Distributed computation

Page 10: Ian huston   getting started with cloud foundry

Data Driven Applications

Page 11: Ian huston   getting started with cloud foundry

11 © Copyright 2015 Pivotal. All rights reserved.

Multi-cloud � Same applications running across different cloud providers:

Private Public Hosted

Page 12: Ian huston   getting started with cloud foundry

12 © Copyright 2015 Pivotal. All rights reserved.

Cloud Foundry Foundation P

LATI

NU

M

GO

LD

SIL

VE

R

Page 13: Ian huston   getting started with cloud foundry

13 © Copyright 2015 Pivotal. All rights reserved.

cf push Pushing your first app

Page 14: Ian huston   getting started with cloud foundry

14 © Copyright 2015 Pivotal. All rights reserved.

Challenge 1: Pushing your first application �  Choose PWS API endpoint: $cfapihttps://api.run.pivotal.io�  Login:$cflogin

� Code directory: 01-simple-python-app� Deploy with

$cfpush

�  Check it worked at http://myapp-RANDOM-WORDS.cfapps.io

�  Turn off your app when finished with cfstopmyapp (but not yet!)

Page 15: Ian huston   getting started with cloud foundry

15 © Copyright 2015 Pivotal. All rights reserved.

Simple Flask App Demo � Simple one page “Hello World” web app � Video: https://www.youtube.com/watch?v=QOfD6tnoAB8 � Demonstrates: –  Installation of requirements –  Scaling properties

� Need to Provide: –  App files –  Dependencies listed in requirements.txt file –  Optional manifest.yml file with configuration for deployment

Page 16: Ian huston   getting started with cloud foundry

C F R O"U"T"E"R

2. Set up domain

Cloud Controller

Instance

1. Upload code

4. Copy app into containerised

instances

3. Install Python &

Dependencies

5. Start app and accept connections

Send request to URL

WHAT JUST HAPPENED?

Source Code

Instance

$cfpush

Browser

5. Load balance between instances

Page 17: Ian huston   getting started with cloud foundry

17 © Copyright 2015 Pivotal. All rights reserved.

What just happened? 1.  Application code is uploaded to CF 2.  Domain URL is set up ready for routing 3.  Cloud controller builds application in container: –  Python interpreter selected –  Dependencies installed with pip

4.  Container is replicated to provide instances 5.  App starts and Router load balances requests �  See what’s happening using logs: $cflogsmyapp--recent

Page 18: Ian huston   getting started with cloud foundry

18 © Copyright 2015 Pivotal. All rights reserved.

Python on Cloud Foundry � First class language (with Go, Java, Ruby, Node.js, PHP) � Automatic app type detection –  Looks for requirements.txt or setup.py

� Buildpack takes care of –  Detecting that a Python app is being pushed –  Installing Python interpreter –  Installing packages in requirements.txt using pip –  Starting web app as requested (e.g. python myapp.py)

Page 19: Ian huston   getting started with cloud foundry

19 © Copyright 2015 Pivotal. All rights reserved.

Scaling memory and instances � We can scale our application as needed in terms of memory

and number of instances:

$cfscalemyapp–i5$cfscalemyapp–m256M

� Check app in browser to see different instances being used. � Scale back down with $cfscalemyapp–i1

Page 20: Ian huston   getting started with cloud foundry

20 © Copyright 2015 Pivotal. All rights reserved.

How does this work? � Containerised application is cached and ready to be

deployed. � Scaling number of instances replicates container and load

balances requests across all instances. � Scaling memory requires restarting app. � Auto-scaling is also possible.

Page 21: Ian huston   getting started with cloud foundry

21 © Copyright 2015 Pivotal. All rights reserved.

Buildpacks Pushing data science apps

Page 22: Ian huston   getting started with cloud foundry

22 © Copyright 2015 Pivotal. All rights reserved.

What are buildpacks? �  Idea and format from Heroku � Responsible for doing whatever is necessary to get your

app running. � Buildpacks take care of –  Detecting which type of application is being pushed –  Installing the appropriate run-time –  Installing required dependencies or other artifacts –  Starting the application as requested

Page 23: Ian huston   getting started with cloud foundry

23 © Copyright 2015 Pivotal. All rights reserved.

Containers vs Buildpacks

runtime layer

OS image

application layer

Container (e.g. Docker)

system brings fixed host OS Kernel

* Devs may bring a custom buildpack

runtime layer*

OS image

application layer

Buildpack

App container

System Provides

Dev Provides

system brings fixed host OS Kernel

Page 24: Ian huston   getting started with cloud foundry

24 © Copyright 2015 Pivotal. All rights reserved.

Community Buildpacks https://github.com/cloudfoundry-community/

cf-docs-contrib/wiki/Buildpacks � Lots of languages:

Clojure, Haskell, .NET, Erlang, Elixir, etc. � RShiny app buildpack:

https://github.com/alexkago/cf-buildpack-r � Can also use some Heroku buildpacks without modification.

Page 25: Ian huston   getting started with cloud foundry

25 © Copyright 2015 Pivotal. All rights reserved.

Using conda for package management � http://conda.pydata.org � Benefits: –  Uses precompiled binary packages –  No fiddling with Fortran or C compilers and library paths –  Known good combinations of main package versions –  Really simple environment management (better than virtualenv) –  Easy to run Python 2 and 3 side-by-side

Go try it out if you haven’t already!

Page 26: Ian huston   getting started with cloud foundry

26 © Copyright 2015 Pivotal. All rights reserved.

Challenge 2: Pushing a PyData app � Code directory: 02-pydata-spyre-app� Spyre – Adam Hajari https://github.com/adamhajari/spyre � This app uses the Pydata buildpack to install Matplotlib,

NumPy and more. � Spyre provides a simple way to build interactive web based

visualisations similar to Rshiny.

Page 27: Ian huston   getting started with cloud foundry

27 © Copyright 2015 Pivotal. All rights reserved.

Next Steps See https://github.com/ihuston/python-cf-examples for continuation of tutorial: � How to bind data sources like Redis & PostgreSQL � Build a simple machine learning API system

Full tutorial as a video: https://www.youtube.com/watch?v=lp2c05yDJko

Page 28: Ian huston   getting started with cloud foundry

28 © Copyright 2015 Pivotal. All rights reserved.

Resources � Docs: http://docs.cloudfoundry.org � CF Summit videos: http://cfsummit.com � Join the CF community: http://cloudfoundry.org � CF meetups: http://cloud-foundry.meetup.com

Page 29: Ian huston   getting started with cloud foundry

29 © Copyright 2015 Pivotal. All rights reserved.

@ianhuston