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.
What happens when I cf push?
- App files sent to CF
- Runnable app artefact is created (droplet)
- 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 requiredDefine in
.cfignore
files that should not be sentNote: 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
Note: Coding Horror wisdom
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
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?
bin/detect
bin/compile
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
- Developer pushes application
- Ordered list of buildpacks detect app compatibility
- Winning buildpack runs compile and release (staging)
- Resulting droplet is store in blobstore
- Droplets are deployed in containers for running apps
How many types of buildpacks?
- Default buildpacks
- Community buildpacks
- Heroku buildpacks
- 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?
- App logs
- App events
- App instrumentation
- 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
- Setup Skylight for app
- Setup Opbeat for app
- Learn about CF Logging and Metrics
- Send app logs to Papertrail
$ 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
Subscribe to:
Posts (Atom)
உப்பு மாங்காய்
சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...
-
கந்தன் வேலைக்குச் சென்று கிட்டத்தட்ட பத்து ஆண்டுகளுக்கு பிறகு சொந்த ஊர் திரும்பி இருந்தான். காளிக் கோயிலைத் தாண்டி தான் அவன் வீட்ட...
-
பிரேமாவின் மூத்த ஆண் குழந்தைக்கு முன் பிறந்த இளைய பெண் குழந்தை அவள். வயலும் சேறும் இரண்டற கலந்த ஊர். முழுதாய் மூன்றாம் வகுப்பைத் ...