Saturday, December 30, 2017

Friday, December 29, 2017

manifest yaml inherit

parent:

---
applications:
- name: foo
buildpack: teapot
child:

---
inherit: parent.yml
applications:
- name: foo
buildpack: kettle

What is Cloud Foundry?

  • An open Platform as a Service (PaaS)
  • Fast and easy to build, test, deploy & scale apps
  • Works with any* language or framework
Find out more at docs.cloudfoundry.org
Note: Open-source with an Apache license, hosted on GitHub.
Developers use the cf command line utility to interact with a CF deployment. The cf cli is pre-built for Windows, Mac and Linux.
CF supports any language or framework through buildpacks. More on that subject later.

How do I target a different org and/or space?

$ cf target -o ORG -s SPACE

What happens when I cf push?

  1. App files sent to CF
  2. Runnable app artefact is created (droplet)
  3. App starts on an app host

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

1. App files sent to CF

By the cf cli, no other dependency required
Define in .cfignore files that should not be sent
Note: cf cli sent all our app files to the Cloud Controller
The Cloud Controller stores all files it receives in the Blob Store
It also stores metadata about the app in the database

2. Runnable app artefact

App Files + Runtime Dependencies = App Artefact
Note: This is done by the Buildpack, part of the staging phase
The majority of the output from a cf push is this staging phase
You will find more about Buildpacks in the next topic

3. App starts on an app host

If it's a web process, it binds to a TCP port

Resilient / High Availability

05 How do I make my app resilient?

This content is copyright of CloudCredo. © CloudCredo 2015. All rights reserved.

Feature

As a CF hero
I want my app to be resilient
So that random failures won't take it offline

Let's ship it

# From the training home directory:
$ cd 05-resilience/imperfect-app
$ cf push

...

urls: imperfect-app-votive-seeress.cfapps.io

...

You've shipped your new app!

The static website is handling the traffic wonderfully
Everyone wants to use your new app, but...

It crashes

Version 1 Sucks, But Ship It Anyway

How to make an app resilient?

Embrace failure & run many instances of the same app
$ cf scale imperfect-app -i 3
$ cf apps

name state instances memory disk urls
imperfect-app started 2/3 64M 256M imperfect..
Note: Because CF is running your app, running many instances of it is just a command away
Notice the different IPs that your app instances are running on...
Even though each DEA runs on a different host, multiple app instances can end up on the same host
The more app instances you have, the less likely that they will be running on the same host
The next generation CF runtime - a.k.a. Diego - does a much better job in regards to evenly distributing the app instances

Many crashed instances, 
app still available

$ cf app imperfect-app

state since cpu memory disk
#0 running 2015-11-02 0.0% 25.3M of 32M 66.9M of 128M
#1 down 2015-11-02 0.0% 0 of 0 0 of 0
#2 down 2015-11-02 0.0% 0 of 0 0 of 0
$ watch cf apps # Watch app instances restart in real-time

What restarts crashed apps?

Health Manager in DEA v2 (a.k.a. HM9K)
Health Check in Diego v3
Note: When an app instance crashes, the Health Manager dubbed HM9K will notice this and restart the app instance

My app needs more memory

$ cf events imperfect-app

description
index: 1, reason: CRASHED... Exited with status 255 (out of memory)
$ cf scale imperfect-app -m 256M

My app needs more disk space

Do not use the app's disk for persistence
$ cf app imperfect-app

state since cpu memory disk
#0 running 2015-11-02 0.0% 24.4M of 256M 95.2M of 256M
#1 running 2015-11-02 0.0% 112.4M of 256M 224.2M of 256M
#0 running 2015-11-02 0.0% 24.3M of 256M 95.2M of 256M
$ cf logs imperfect-app --recent

Errno::EDQUOT - Disk quota exceeded @ io_write - infinite-file:
$ cf scale imperfect-app -k 1G
Note: Use a service for persistence, do not store any files in the container that runs the app

Scale instances, disk & memory

Combine multiple options in a single command
$ cf help scale

NAME:
scale - Change or view the instance count, disk space limit...

USAGE:
cf scale APP_NAME [-i INSTANCES] [-k DISK] [-m MEMORY] [-f]

OPTIONS:
-i Number of instances
-k Disk limit (e.g. 256M, 1024M, 1G)
-m Memory limit (e.g. 256M, 1024M, 1G)
-f Force restart of app without prompt

Buildpacks

04 What are buildpacks?

This content is copyright of CloudCredo. © CloudCredo 2015. All rights reserved.

Feature

As a CF hero
I want a simple static website
So that I can focus on building my product

What are buildpacks?

A Cloud Foundry component that 
resolves your app's runtime dependencies

Why buildpacks?

  • Simplify app deployment - focus on your code
  • Fewer files, quicker app deploys
  • Produce self-contained, runnable app artefacts

What does a buildpack do?

  • Input is the application code
  • Examines application and fulfils dependencies
  • Output is a droplet
  • Metadata output defines ENV vars and start command
Each buildpack participates in election

How does a buildpack work?

  1. bin/detect
  2. bin/compile
  3. bin/release

Where does the buildpack run?

  • Uses the host kernel with a rootfs (jeos)
  • Default rootfs is cflinuxfs2 (based on Ubuntu 14.04 Trusty)
  • Buildpack execution and app runtime are in containers
  • Cloud Foundry uses Garden for containerisation

Cloud Foundry 
deployment flow 
revisited

  1. Developer pushes application
  2. Ordered list of buildpacks detect app compatibility
  3. Winning buildpack runs compile and release (staging)
  4. Resulting droplet is store in blobstore
  5. Droplets are deployed in containers for running apps

How many types of buildpacks?

  1. Default buildpacks
  2. Community buildpacks
  3. Heroku buildpacks
  4. Custom buildpacks
Online and Offline

1. Default buildpacks

$ cf buildpacks

buildpack position filename
ruby_buildpack 1 ruby_buildpack-cached-v1.6.7
nodejs_buildpack 2 nodejs_buildpack-cached-v1.5.0
java_buildpack 3 java-buildpack-v3.2
go_buildpack 4 go_buildpack-cached-v1.6.2
liberty_buildpack 5 liberty_buildpack
python_buildpack 6 python_buildpack-cached-v1.5.1
php_buildpack 7 php_buildpack-cached-v4.1.4
staticfile_buildpack 8 staticfile_buildpack-cached-v1.2..
binary_buildpack 9 binary_buildpack-cached-v1.0.1

2. Community buildpacks


3. Heroku buildpacks

  • CF buildpacks are based on them
  • They are interchangeable* (mostly)

4. Custom buildpacks

  • Your own language deserves its own buildpack
  • As simple or as complicated as you want

Static buildpack

# From the training home directory:
$ cd 04-buildpacks/static-app
$ cf push
$ cf app static-app

state since cpu memory disk
#0 running 2015-11-02 0.0% 6.5M of 16M 33.6M of 64M

Scale app with ease

$ cf scale static-app -i 32
$ cf app static-app

state since cpu memory disk
#0 running 2015-11-02 0.0% 6.5M of 16M 33.6M of 64M
#1 starting 2015-11-02 0.0% 0 of 16M 0 of 64M
#2 running 2015-11-02 0.0% 6.9M of 16M 33.5M of 64M
...
#30 running 2015-11-02 0.0% 6.8M of 16M 33.5M of 64M
#31 running 2015-11-02 0.0% 7M of 16M 33.6M of 64M

DELIVERED

As a CF hero
I want a simple static website
So that I can focus on building my product

Debug CF

06 How do I debug my app?

This content is copyright of CloudCredo. © CloudCredo 2015. All rights reserved.

Feature

As a CF hero
I want to know what my CF app is doing
So that I can debug it

Push a buggy app

# From the training home directory:
$ cd 06-debugging/debug-app
$ cf push

...

urls: debug-app-unerring-muddlehead.cfapps.io

...

How do I debug my app?

  1. App logs
  2. App events
  3. App instrumentation
  4. SSH access

1. App logs

$ cf logs debug-app --recent

...

... [App/0] ERR ... - RuntimeError - I am a bug, fix me:
... [App/0] ERR /home/vcap/app/config.ru:20:in `block in <class:Web>
$ cf logs debug-app # Tails app logs, CTRL + C to exit

Let's fix the app

$ cf set-env debug-app FIXED true
$ cf restart debug-app

2. App events

$ cf events debug-app

... description
... index: 0, reason: CRASHED, exit_description: 2 error(s) ...
...
Note: Notice that the most recent event is at the top

3. App instrumentation

  • New Relic
  • AppDynamics
Included in Java buildpack

New Relic instrumentation

$ cf create-service newrelic standard newrelic
$ cf bind-service debug-app newrelic
$ cf env debug-app
# Find your New Relic license key
# From the training home directory:
$ cd 06-debugging/debug-app
# Replace YOUR-LICENSE-KEY
$ vim newrelic.yml
$ cf push
$ cf service newrelic
Note: Create a New Relic service instance
Provide app with New Relic license key
Find New Relic Dashboard URL
Generate some load

4. SSH access

$ cf ssh debug-app

DELIVERED

As a CF hero
I want to know what my CF app is doing
So that I can debug it

Any questions?

Questions cannot be stupid. Answers can.

CF SUPERHERO

$ cf cups logdrain -l syslog://YOUR-PAPERTRAIL-LOG-DESTINATION
$ cf bind-service debug-app logdrain
# Check your Papertrail Events, no need to restart the app

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...