Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Pivotal Cloud Foundry

Intro to Pivotal Cloud Foundry

Michael Cheng

August 05, 2016
Tweet

More Decks by Michael Cheng

Other Decks in Programming

Transcript

  1. Pivotal Cloud Foundry
    A Developer’s Perspective

    View Slide

  2. Cloud Computing

    View Slide

  3. What is Cloud Foundry?
    • Cloud Foundry is a open source
    PaaS software.
    • Cloud Foundry is a platform for
    developing and running cloud
    applications.
    • 12 Factor Apps (http://12factor.net)

    View Slide

  4. What is Cloud Foundry?
    • Works with many languages and
    frameworks.
    • A platform that allows you to
    automatically provision resources.
    • Enables continuous integration/
    continuous delivery.
    • Allows you to focus on writing cloud
    native applications.

    View Slide

  5. Languages Supported
    • Java - Grails, Play, Spring, or any other JVM-based language or framework
    • Ruby - JRuby, Rack, Rails, or Sinatra
    • Node.js - Node or JavaScript
    • Binary
    • Go
    • PHP - Cake, Symfony, Zend, Nginx, or HTTPD
    • Python - Django or Flask
    • Staticfile - HTML, CSS, JavaScript, or Nginx

    View Slide

  6. What is Pivotal Cloud Foundry?
    • Pivotal Cloud Foundry is a reference
    implementation of Cloud Foundry for
    the enterprise.
    • Open source software provides the
    basis for the Pivotal Cloud Foundry
    platform.
    • Pivotal offers additional commercial
    features, enterprise services,
    support, docs, certs, etc.

    View Slide

  7. Cloud Foundry vs PCF
    • PCF is easier to install
    • Has nicer web GUI.
    • Additional features like auto-scaling,
    LDAP/AD (SAML) support, metrics
    server, notifications, Ops Metrics.
    • Many of the services come installed
    by default (MongoDB, Neo4J,
    RabbitMQ, Redis, etc).
    vs

    View Slide

  8. View Slide

  9. Pivotal Web Services (PWS)
    • Hosted version of PCF.
    • Exactly the same user experience /
    features.
    • Register for a free trial account.
    • http://run.pivotal.io
    • (Recommend using Chrome)

    View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. Organization
    Spaces
    Logical way of organising users and resources

    View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. Using PCF
    • Mainly interface using the Command Line Interface (CLI)
    • Download the CF CLI here: https://console.run.pivotal.io/2/tools
    • Alternative download: https://github.com/cloudfoundry/
    cli#downloads

    View Slide

  23. View Slide

  24. Installation (Windows)
    • Unzip and copy cf to C:\windows
    • Add the following environment variables:
    • CF_HOME=C:\Users\\
    • https_proxy=http://
    :@proxy.singaporepower.com.sg:8080
    • Example:
    • CF_HOME=C:\Users\PMCC749I\
    • https_proxy=http://PMCC749I:[email protected]:8080

    View Slide

  25. Login to PWS
    • Start Terminal ( + R, type ‘cmd’)
    • cf -v (gets version)
    • cf help (gets list of commands)
    • cf help
    • cf login -a api.run.pivotal.io
    • cf target (find out which server)
    • You will be prompted for your Email
    and Password.

    View Slide

  26. Create a PHP App
    • cd \Users\\
    • mkdir demo
    • cd demo
    • notepad index.php

    View Slide

  27. Publish App
    • cf push
    • eg. cf push sp-miccheng-demo1
    • Visit the website: http://.cfapps.io
    • eg. http://sp-miccheng-demo1.cfapps.io

    View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. What happens when you cf push?
    1. Files in folder / local build artefacts are uploaded to CF (PWS).
    2. Auto detection of type of apps you are deploying, appropriate
    buildpack is installed and a “droplet” (Cloud Foundry unit of
    execution) is build.
    3. Droplet build in a staging area and stored in blob store.
    4. Droplet is deployed to droplet execution agent and application is
    started (route is allotted).

    View Slide

  33. Buildpacks
    • Buildpacks are used to detect the type of application you are
    deploying.
    • It sets up the the proper execution environment on Cloud Foundry.
    • Only used during the build / staging time - not in the running app.
    • See available buildpacks: cf buildpacks

    View Slide

  34. Hostname & Domains
    • All CF apps use a shared domain by default (eg. cfapps.io).
    • When we deploy an app, we also declare a hostname (eg. sp-
    miccheng-demo1).
    • The combo and hostname + domain = route
    • Hostname can be configured in CLI or manifest.yml.
    • You can also add custom routes manually to apps.

    View Slide

  35. Application Start Command
    • Each buildpack has a default command to start your application.
    • To override default start command:
    • cf push my-app -c “node server.js”
    • To reset to the buildpack start command:
    • cf push my-app -c “null”

    View Slide

  36. Deployment Manifest
    • Application manifests tell cf push what to do with applications.
    • This includes everything from how many instances to create and
    how much memory to allocate to what services applications should
    use.
    • YAML format.
    • Online Generator: http://cfmanigen.mybluemix.net

    View Slide

  37. Scaling a CF app
    • Horizontal scaling - adding more instanced
    • cf scale -i
    • Vertical scaling - adjust disk space limit and memory limit
    • cf scale -k 512M
    • cf scale -m 1G

    View Slide

  38. Scaling Horizontally
    • cf push
    • cf scale -i 2

    View Slide

  39. Environment Variables
    • Application configurations as environment variables.
    • How CF runtime communicates with a deployed app about the
    environment.
    • cf env
    • Use the manifest file to add environments.
    • You can also set using CLI: cf set-env OMG “oh my god”

    View Slide

  40. Using Services
    • View what kinds of services are available
    • cf marketplace
    • Creating a service instance
    • cf create-service
    • Example: cf create-service elephantsql turtle miccheng-db

    View Slide

  41. Using Services
    • See created services: cf services
    • See details of a service: cf service
    • Bind service instance to app instances:
    • cf bind-service
    • This will add env variables to the app instances.

    View Slide

  42. Logs / Events
    • Tailing logs: cf logs
    • Recent logs: cf logs --recent
    • Logs can be drained to external log aggregators (eg. PaperTrail,
    Splunk)
    • Significant System Events: cf events

    View Slide

  43. Login to app container
    • All apps run in a linux container (LXC)
    • You can SSH into the container if you need to take a look at what’s
    going on (eg. troubleshooting, verify file version, etc)
    • cf ssh -i

    View Slide

  44. Hands-On
    https://github.com/miccheng/rails-guestbook-demo

    View Slide

  45. More things…
    • User-provided services - enable developers to use services that are
    not available in the marketplace with their applications running on
    Cloud Foundry.

    (Reference: http://docs.pivotal.io/pivotalcf/1-7/devguide/services/user-provided.html)
    • Managed Services for Cloud Foundry - services integrated with
    Cloud Foundry via APIs, and enable end users to provision reserved
    resources and credentials on demand.

    (Reference: http://docs.pivotal.io/pivotalcf/1-7/services/index.html)

    View Slide

  46. Q&A

    View Slide

  47. Michael Cheng
    @CoderKungfu
    [email protected]

    View Slide