Cloud Foundry For Beginners

Cloud Foundry : From Zero to Hero

Part 1.

What is Cloud Foundry?

How can I access Cloud Foundry?

What are we going to do?


CF Logo
  • Overview
  • CF Foundation
  • Distributions

The open platform

Cloud Foundry Overiew

What is…

  • Initial release in 2011
  • An open Cloud Native Platform
  • Application Runtime and Container Runtime
  • Fast and easy to build, test, deploy & scale apps
  • Works with any language or framework
  • Available as open source, commercial distributions or hosted offerings

Application Runtime

What is the Application Runtime?

Application Runtime is PaaS

  • Cloud Computing taxonomy: IaaS, PaaS, and SaaS
  • PaaS aims to improve developer productivity
  • Reduces undifferentiated ‘plumbing’ aka ‘yak shaving’
  • Heroku blazed a trail for PaaS and 12 Factor apps
  • Applications are the Cloud Native unit of currency

Explaining Cloud Native

Why a Cloud Native Platform?

What characterises Cloud Native?

  • 12 Factor architectural style
  • Embracing low cost of change in cloud
  • Fast feedback and small batch sizes

Container Runtime

What is the Container Runtime?

Container Runtime is Kubernetes

  • Runs pre-built container images
  • Good for running other people’s code
  • Suited to lift ‘n’ shift, non-cloud-native systems

Explaining Cloud Native

Why a Cloud Native Platform?

Why a Cloud Native Platform?

  • Don’t waste time on plumbing infrastructure
  • Deliver business value more often
  • Learn about your customers more quickly

The open source cloud native platform

CF Foundation

60+ industry leading member companies!

The open source cloud native platform

Open Source Distribution

CF Logo
Where can you get Open Source Cloud Foundry?

Cloud Portability & the Open Core Model

Certified Providers

Lab 1.

I can log into Cloud Foundry

Part 2.

Interacting with Cloud Foundry

How can I interact with Cloud Foundry?

What are we going to do?


CF Logo
  • Interacting with the CLI
  • Orgs, spaces, quotas and apps

Command Line Interface

cf CLI

How do I interact with CF?

  • Command Line Interface (CLI): from terminal / command prompt

  • IDE plugins

  • Vendor specific web user interfaces

  • CI tool integration (e.g

Apps & Services in Cloud Foundry


Every application and service is scoped to a space

$ cf spaces
$ cf space <some-space> # for details

    Org:               cf-hero
    Security Groups:   public_networks, dns, ssh-logging, p-mysql...
    Space Quota:

Multitenancy in Cloud Foundry


Organisations segregate tenants in a Cloud Foundry installation.

$ cf orgs
$ cf org pcfdev-org
Getting info for org pcfdev-org as admin...

              quota:          default (102400M memory limit, unlimited instance memory limit, 1000 routes, -1 services, paid services allowed, unlimited app instance limit, 0 route ports)
              spaces:         pcfdev-space
              space quotas:

Limiting Resources


Quotas provide resource limits to orgs and spaces

$ cf quotas

name           total mem   instance mem   routes   service instances
free           0           unlimited      1000     0
trial          2G          unlimited      1000     10
paid           10G         unlimited      1000     unlimited
25GB           25G         unlimited      1000     unlimited
50GB           50G         unlimited      1000     unlimited
75GB           75G         unlimited      1000     unlimited
100GB          100G        unlimited      1000     unlimited

Bringing it altogether

Orgs, Spaces and Apps

What is the relationship between orgs, spaces & apps?

orgs and spaces


Bringing it altogether

Orgs, Spaces and Apps

Run cf target to confirm your org and current space.

$ cf target

API endpoint: (API version: 2.54.0)
User:           admin
Org:            cf-hero
Space:          training

Lab 2.

I can interact with Cloud Foundry

Part 3.

Pushing Your First App

How can I run my code in Cloud Foundry?

What are we going to do?


CF Logo
  • cf push basics
  • Staging
  • Running

The Magic of CF Push

Deploying Apps

What happens when I cf push?

  1. Upload: App files sent to CF
  2. Staging: Executable artifact is created (droplet)
  3. Running: App starts on an app host

App receives web requests (if it binds to TCP port)

The Magic of CF Push

Deploying Apps

cf push explained

Getting ready to run


Buildpacks create a runnable artifact called a droplet

  App Files + Runtime Dependencies = App Artifact (droplet)

Executing application instances


Apps are started on specialized VMs called cells

  • If it’s a web process, it binds to a TCP port
  • Instances are distributed across multiple cells
  • Router distributes traffic across instances

Where does the app run?

routing to apps

Separating build and run stages

12 Factor


V. Build, release, run

Strictly separate build and run stages

Lab 3.

I can access my app on a public URL

Part 4.


What does Cloud Foundry do to my code to make my app runnable?

What are we going to do?


CF Logo
  • Why Buildpacks?
  • How they work
  • Types of Buildpacks

Runtime Dependencies in Cloud Foundry


Buildpack: A Cloud Foundry component that resolves your app’s runtime dependencies

Standardizing runtime and deployment

Why Buildpacks?

Why buildpacks?

  • Simplify app deployment -> focus on your code
  • Fewer files, quicker app deploys
  • Produce self-contained, runnable and cacheable app artifacts

Standardizing runtime and deployment

How do they work?

Given: An Application

Execute: A set of script endpoints against the app

  • bin/detect: Can I handle this? (introspection)
  • bin/supply: If yes, provide the dependencies
  • bin/finalize: Prepare the app for launch - runs only for the last buildpack
  • bin/release: Build the metadata (env variables, start command, etc)

A haiku...

"here is my source code
run it on the cloud for me
i do not care how"

Onsi Fakhouri

VP Cloud R&D, Pivotal


Types of Buildpacks

  • Default buildpacks (included in the platform)
  • Community buildpacks: Leverage the community
  • Custom buildpacks: Build your own



Online: Downloads dependencies as needed


Offline: All possible dependencies included (behind the firewall)

Lab 4.

I can push apps without caring how runtime dependencies are provided

Part 5.

Resilience and Availability

How can I make my app resilient?

What are we going to do?


CF Logo
  • Resilience
  • Health Management

How do you configure an app deployment for resilience?

Embrace failure & run many instances of the same app

$ cf scale imperfect-app -i 3
$ cf apps

name            state     instances
imperfect-app   started   2/3         

What happens when instances fail?

They are automatically recreated by comparing desired state to actual state

Components used in cf scale:

  • nsync: gets message from CC (after cf scale). Writes the DesiredLRP value in BBS.

  • Cell Rep Monitors containers to get the ActualLRP value

  • BBS: Monitors DesiredLRP vs ActualLRP and kills/launches instances.

Lab 5.

As an app user

I can still use the app even if an instance crashes

Part 6.


How can I investigate problems with my app?

What are we going to do?


CF Logo
  • Debugging basics & info sources
  • 3rd party instrumentation

Where to go for information

Debugging Basics

How do I debug my app?

  • cf logs App logs
  • cf events App events
  • cf ssh SSH access to the app container

3rd Party Integration


CF contains hooks to enable 3rd party integrations

  • AppDynamics
  • New Relic
  • PWS console (built in)

AppDynamics and New Relic agents are included in Java buildpack

Lab 6.

I can investigate my apps to determine the cause of errors

Part 7.

Dealing with State

How can I share persistent data between app instances?

What are we going to do?


CF Logo
  • Handling State in Applications
  • Marketplace & Brokers
  • Binding to apps

Where should my app store state?

In an external service.

  • Horizontal scale (adding instances)
  • Eliminate costly routing overhead (sticky sessions are supported)
  • Leverage services in the marketplace

What is a Service Broker?

  • Brokers access to resources of a specific type

  • Implements a rest API advertising a catalog of service offerings and plans

How do I see all available service offerings?

$ cf marketplace
service          plans               description

cleardb          spark, boost*, ...  Highly available MySQL for y...
cloudamqp        lemur, tiger*, ...  Managed HA RabbitMQ servers ...
elephantsql      turtle, panda*, ..  PostgreSQL as a Service     ...
ironworker       large*,        ...  Scalable Background and Asyn...
loadimpact       lifree, li100*, ..  Automated and on-demand perf...
memcachedcloud   100mb*, 250mb*, ..  Enterprise-Class Memcached f...
mongolab         sandbox        ...  Fully-managed MongoDB-as-a-S...
newrelic         standard       ...  Manage and monitor your apps...
rediscloud       100mb*, 250mb*, ..  Enterprise-Class Redis for D...
searchly         small*, micro*, ..  Search Made Simple. Powered-...
sendgrid         free, bronze*,  ..  Email Delivery. Simplified.

How are service credentials
exposed to applications?

$ cf env stateful-app

  "rediscloud": [
    "credentials": {
     "hostname": "",
     "password": "HITHERE",
     "port": "15708"

Through the Environment!

12 Factor
  • III. Config: Store config in the environment
  • IV. Backing services: Treat backing services as attached resources

Lab 7.

I can share persistent data between app instances

Part 8.

Domains and Routes

How can I deploy with zero downtime?

What are we going to do?


CF Logo
  • Routes
  • Zero-downtime Deployments
  • Custom Domains
  • Internal Domains
  • Route Services

Route: A URL on which an application can be accessed.

Many to Many Relationship between apps & routes.

Zero-downtime Deployments
  • Deploy a new version of your app.
  • Map the route to it
  • Validate
  • Unmap from the old version

Domains: provide a namespace from which to create routes

  • Shared domain: for all of CF
  • Private domain: scoped to an Org
  • Requires DNS to be configured

Internal domains allow apps to communicate directly

  • Requests to regular routes go ‘out and back in’
  • Requests to internal domains go app-to-app
  • Allows DNS-based ‘service discovery’

Route Services transform or process requests before they reach an app

  • Bound to routes, not apps
  • Can be re-used between apps
  • Use cases:
    • Authentication
    • Rate limiting
    • Caching
  • Not for internal domains

Lab 8.

As an app user, I see no downtime when the app is updated


Speed    |    Simplicity    |    Control